/*
 ***************************************************************************
 * MediaTeK Inc.
 * 4F, No. 2 Technology	5th	Rd.
 * Science-based Industrial	Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2012, MTK.
 *
 * All rights reserved.	MediaTeK's source	code is	an unpublished work	and	the
 * use of a	copyright notice does not imply	otherwise. This	source code
 * contains	confidential trade secret material of MediaTeK Tech. Any attemp
 * or participation	in deciphering,	decoding, reverse engineering or in	any
 * way altering	the	source code	is stricitly prohibited, unless	the	prior
 * written consent of MediaTeK, Inc. is obtained.
 ***************************************************************************

	Module Name:
	omci_me_multicast_func.c

	Abstract:

	Revision History:
	Who			When			What
	--------	----------		----------------------------------------------
	Name		Date			Modification logs
	wayne.lee	2012/7/28	Create
*/


#include <stdlib.h>
#include <string.h>
#include "omci_me_multicast.h"
#include "omci_me_mac_bridge.h"
#include "libcompileoption.h"
#include "lib_xpon_igmp.h"

#define MCAST_SRV_PKT_TBL_LEN     20
#define MCAST_OP_PROF_OFFSET      10
#define MCAST_SRV_PKT_TBL_MASK    0x0400

#define XPONIGMP_PORT_VEIP_ID     0      //for VEIP id


int setMOPMulticastVersionValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastFuncValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastFastLeaveValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastUpstreamTCIValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastTagCtrlValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastUpstreamRateValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastDynamicAclTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastStaticAclTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastRobustnessValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastQuerierIPAddressValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastQueryIntervalValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastQueryMaxResponseTimeValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastLastMemberQueryIntervalValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastUnauthorizedJoinRequestValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMOPMulticastDownstreamIGMPAndTCIValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int omci_me_multicast_pro_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info);


int setMSCmeTypeValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMSCOperationProfileValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMSCMaxSimultaneousGroupValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMSCMaxBandwidthValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMSCBWEnforcementValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int setMSCBWsrvPktTblValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int omci_me_multicast_sbs_cfg_info_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info);

int getMSMCurrMultBandwidthValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMSMJoinMesgCounterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMSMBandExceCounterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMSMIpv4ActiveGroupTblValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);
int getMSMIpv6ActiveGroupTblValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr);

/*******************************************************************************************************************************
9.3.27 multicast operations profile

********************************************************************************************************************************/
static attribute_func_t MOPMulticastVersionGetSetFunc = {
	NULL,
	setMOPMulticastVersionValue,
};

static attribute_func_t MOPMulticastFuncGetSetFunc = {
	NULL,
	setMOPMulticastFuncValue,
};

static attribute_func_t MOPMulticastFastLeaveGetSetFunc = {
	NULL,
	setMOPMulticastFastLeaveValue,
};

static attribute_func_t MOPMulticastUpstreamTCIGetSetFunc = {
	NULL,
	setMOPMulticastUpstreamTCIValue,
};

static attribute_func_t MOPMulticastTagCtrlGetSetFunc = {
	NULL,
	setMOPMulticastTagCtrlValue,
};

static attribute_func_t MOPMulticastUpstreamRateGetSetFunc = {
	NULL,
	setMOPMulticastUpstreamRateValue,
};

static attribute_func_t MOPMulticastDynamicAclTableGetSetFunc = {
	NULL,//	getMOPMulticastDynamicAclTableValue, not need in OMCI2.0
	setMOPMulticastDynamicAclTableValue,
};

static attribute_func_t MOPMulticastStaticAclTableGetSetFunc = {
	NULL,//	getMOPMulticastStaticAclTableValue, not need in OMCI2.0
	setMOPMulticastStaticAclTableValue,
}; 

static attribute_func_t MOPMulticastRobustnessGetSetFunc = {
	NULL,
	setMOPMulticastRobustnessValue,
}; 

static attribute_func_t MOPMulticastQuerierIPAddressGetSetFunc = {
	NULL,
	setMOPMulticastQuerierIPAddressValue,
}; 

static attribute_func_t MOPMulticastQueryIntervalGetSetFunc = {
	NULL,
	setMOPMulticastQueryIntervalValue,
}; 

static attribute_func_t MOPMulticastQueryMaxResponseTimeGetSetFunc = {
	NULL,
	setMOPMulticastQueryMaxResponseTimeValue,
}; 

static attribute_func_t MOPMulticastLastMemberQueryIntervalGetSetFunc = {
	NULL,
	setMOPMulticastLastMemberQueryIntervalValue,
}; 

static attribute_func_t MOPMulticastUnauthorizedJoinRequestGetSetFunc = {
	NULL,
	setMOPMulticastUnauthorizedJoinRequestValue,
}; 

static attribute_func_t MOPMulticastDownstreamIGMPAndTCIGetSetFunc = {
	NULL,
	setMOPMulticastDownstreamIGMPAndTCIValue,
};

omci_attr_dscp_t omci_attr_multicast_op_prof_op[]={
	{0, "Managed entity id" ,               2,  ATTR_ACCESS_R_SET_CREATE ,      ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &generalAttrFunc},	
	{1, "IGMP version" ,                    1,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastVersionGetSetFunc},
	{2, "IGMP function" ,                   1,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastFuncGetSetFunc},	
	{3, "immediate leave" ,                 1,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastFastLeaveGetSetFunc},	
	{4, "Upstream IGMP TCI" ,               2,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastUpstreamTCIGetSetFunc},	
	{5, "Upsteam IGMP tag control" ,        1,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastTagCtrlGetSetFunc},	
	{6, "Upstream IGMP rate" ,              4,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastUpstreamRateGetSetFunc},	
	{7, "Dynamic access control table" ,    24, ATTR_ACCESS_R_W,                ATTR_FORMAT_TABLE,        ATTR_FULLY_SUPPORT,  &MOPMulticastDynamicAclTableGetSetFunc},	
	{8, "static access control table" ,     24, ATTR_ACCESS_R_W,                ATTR_FORMAT_TABLE,        ATTR_FULLY_SUPPORT,  &MOPMulticastStaticAclTableGetSetFunc},	
	{9, "Lost groups list table" ,          10, ATTR_ACCESS_R,                  ATTR_FORMAT_TABLE,        ATTR_FULLY_SUPPORT,  &generalAttrFunc},	
	{10,"Robustness" ,                      1,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastRobustnessGetSetFunc},	
	{11,"Querier IP address" ,              4,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_STRING,   	  ATTR_FULLY_SUPPORT,  &MOPMulticastQuerierIPAddressGetSetFunc},	
	{12,"Query interval" ,                  4,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastQueryIntervalGetSetFunc},	
	{13,"Query max response time" ,         4,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastQueryMaxResponseTimeGetSetFunc},	
	{14,"Last member query interval" ,      4,  ATTR_ACCESS_R_W,                ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastLastMemberQueryIntervalGetSetFunc},	
	{15,"Unauthorized join request" ,       1,  ATTR_ACCESS_R_W ,               ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,  &MOPMulticastUnauthorizedJoinRequestGetSetFunc},	
	{16,"Downstream IGMP and TCI" ,         3,  ATTR_ACCESS_R_W_SET_CREATE ,    ATTR_FORMAT_STRING,   	  ATTR_FULLY_SUPPORT,  &MOPMulticastDownstreamIGMPAndTCIGetSetFunc},	
	{255, "", 							    0,  0,                              0,                        0,                    NULL}
};

omci_me_func_t omci_me_multicast_op_prof_op ={
	omci_me_general_create_op,
	omci_me_multicast_pro_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_multicast_op_profile_t omci_multicast_op_prof_attr_data = {0};

omci_attr_t omci_multicast_op_prof_attr={
	(uint8_t *)&omci_multicast_op_prof_attr_data,
	sizeof(omci_multicast_op_prof_attr_data),
};

/*******************************************************************************************************************************
9.3.28 multicast subscriber config info

********************************************************************************************************************************/
attribute_func_t mscMeTypeFunc = {
	NULL,
	setMSCmeTypeValue
};
attribute_func_t mscOperationProfileFunc = {
	NULL,
	setMSCOperationProfileValue
};
attribute_func_t mscMaxSimultaneousGroupFunc = {
	NULL,
	setMSCMaxSimultaneousGroupValue
};
attribute_func_t mscMaxBandwidthFunc = {
	NULL,
	setMSCMaxBandwidthValue
};
attribute_func_t mscBWEnforcementFunc = {
	NULL,
	setMSCBWEnforcementValue
};

attribute_func_t srvPktTbleFunc = {
	NULL,
	setMSCBWsrvPktTblValue
};

omci_attr_dscp_t omci_attr_multicast_subs_cfg_info_op[]={
	{0, "Managed entity id",            2,  ATTR_ACCESS_R_SET_CREATE,       ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	 &generalAttrFunc},	
	{1, "ME type",                      1,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	 &mscMeTypeFunc},
	{2, "operations profile pointer",   2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT, 	 &mscOperationProfileFunc},
	{3, "Max simultaneous groups",      2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	 &mscMaxSimultaneousGroupFunc},
	{4, "Max multicast bandwidth",      4,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	 &mscMaxBandwidthFunc},
	{5, "Bandwidth enforcement",        1,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	 &mscBWEnforcementFunc},	
	{6, "service package table",        20, ATTR_ACCESS_R_W,                ATTR_FORMAT_TABLE,        ATTR_FULLY_SUPPORT, 	 &srvPktTbleFunc},
	{7, "preview groups table",         22, ATTR_ACCESS_R_W,                ATTR_FORMAT_TABLE,        ATTR_FULLY_SUPPORT, 	 &generalAttrFunc},	
	{255, "", 							0,  0,                              0,                        0,                    NULL}
};
omci_me_func_t omci_me_multicast_subs_cfg_info_op ={
	omci_me_general_create_op,
	omci_me_multicast_sbs_cfg_info_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_multicast_subs_cfg_info_t omci_multicast_subs_cfg_info_attr_data = {0};

omci_attr_t omci_multicast_subs_cfg_info_attr={
	(uint8_t *)&omci_multicast_subs_cfg_info_attr_data,
	sizeof(omci_multicast_subs_cfg_info_attr_data),
};

/*******************************************************************************************************************************
9.3.29 multicast subscriber monitor

********************************************************************************************************************************/
attribute_func_t mscCurrMultBandwidthFuc = {
	getMSMCurrMultBandwidthValue,
	NULL
};
attribute_func_t mscJoinMesgCounterFuc = {
	getMSMJoinMesgCounterValue,
	NULL
};
attribute_func_t mscBandExceCounterFunc = {
	getMSMBandExceCounterValue,
	NULL
};
attribute_func_t mscIpv4ActiveGroupTblFunc = {
	getMSMIpv4ActiveGroupTblValue,
	NULL
};
attribute_func_t mscIpv6ActiveGroupTblFunc = {
	getMSMIpv6ActiveGroupTblValue,
	NULL
};

omci_attr_dscp_t omci_attr_multicast_subs_monitor_op[]={
	{0, "Managed entity id",            2,  ATTR_ACCESS_R_SET_CREATE,       ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},	
	{1, "ME type",                      1,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	&generalAttrFunc},
	{2, "Current multicast bandwidth",  4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	&mscCurrMultBandwidthFuc},	
	{3, "Join messages counter",        4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	&mscJoinMesgCounterFuc},	
	{4, "Bandwidth exceeded counter",   4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT, 	&mscBandExceCounterFunc},	
	{5, "IPv4 active group table",      24, ATTR_ACCESS_R,                  ATTR_FORMAT_TABLE,        ATTR_FULLY_SUPPORT, 	&mscIpv4ActiveGroupTblFunc},
	{6, "IPv6 active group table",      58, ATTR_ACCESS_R,                  ATTR_FORMAT_TABLE,        ATTR_FULLY_SUPPORT, 	&mscIpv6ActiveGroupTblFunc},	
	{255, "", 							0,  0,                              0,                        0,                    NULL}
};

omci_me_func_t omci_me_multicast_subs_monitor_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
};

omci_multicast_subs_monitor_t omci_multicast_subs_monitor_attr_data = {0};

omci_attr_t omci_multicast_subs_monitor_attr={
	(uint8_t *)&omci_multicast_subs_monitor_attr_data,
	sizeof(omci_multicast_subs_monitor_attr_data),
};

/*******************************************************************************************************************************
general function

********************************************************************************************************************************/
/*******************************************************************************************
**function name
	getLanPortByMeType
**description:
	get lan port information according 9.3.28 or 9.3.29  MeType attribute.
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	instanceId :	9.3.28 multicast subscriber config info ME or 9.3.29 multicast subscriber monitor  instance id
  	meType:	9.3.28 or 9.3.29 meType value
  	portFlag: 1:get a lan port id, 2: need set all lan port.
  	portId: when port Flag is 1, return lan port id.
  	
********************************************************************************************/
static int getLanPortByMeType(IN uint16_t instanceId, IN uint8_t meType, OUT uint8_t *portFlag, OUT uint16_t *portId){
	int ret = -1;
	int ifaceType = 0;
	uint8_t tempPortId = 0;
	uint8_t ifcType = 0;

	if((meType == OMCI_MULTICAST_CONFIG_INFO_ME_TYPE_0)
		|| (meType == OMCI_MULTICAST_CONFIG_INFO_ME_TYPE_1)){
		//nothing
	}else{
		ret = -1;
		goto end;
	}

	if((portFlag == NULL) || (portId == NULL)){
		ret = -1;
		goto end;
	}

	if(meType == OMCI_MULTICAST_CONFIG_INFO_ME_TYPE_0){//9.3.4 mac bridge port config data ME
		/*get mac bridge port interface type*/
		ifaceType = getMacBridgePortInstType(instanceId, &ifcType);
		if(ifaceType == -1){
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getLanPortByMeType-> getMacBridgePortInstType fail");
			goto end;
		}
		/*get  mac bridge port  ANI/UNI port id*/
		if(ifaceType == OMCI_MAC_BRIDGE_PORT_LAN_IFC && OMCI_MAC_BRIDGE_PORT_VEIP == ifcType){//lan, VEIP port
			*portId = XPONIGMP_PORT_VEIP_ID; 
			*portFlag = OMCI_MULTICAST_ONE_PORT_FLAG;
		}
		else if(ifaceType == OMCI_MAC_BRIDGE_PORT_LAN_IFC){//lan, UNI port
			ret = getMacBridgeLanPortId(instanceId, &tempPortId);
			if(ret != 0){
				ret = -1;
				omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getLanPortByMeType-> getMacBridgeLanPortId fail");
				goto end;
			}
			*portId = (uint16_t)tempPortId;
			*portFlag = OMCI_MULTICAST_ONE_PORT_FLAG;
		}else if(ifaceType == OMCI_MAC_BRIDGE_PORT_WAN_IFC){//wan , ANI port
			*portId = 0;
			*portFlag  = OMCI_MULTICAST_ALL_PORT_FLAG;
		}else{
			//no happen
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getLanPortByMeType-> getMacBridgePortInstType  fail, no happen");
			goto end;
		}
				
	}else if(meType == OMCI_MULTICAST_CONFIG_INFO_ME_TYPE_1 ){//9.3.10 802.1p
		*portId = 0;
		*portFlag  = OMCI_MULTICAST_ALL_PORT_FLAG;
	}
	
	ret = 0;
end:
#if 0
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getLanPortByMeType-> ret=0x%02x",ret);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getLanPortByMeType-> instanceId =0x%02x",instanceId);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getLanPortByMeType-> meType =0x%02x",meType);	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getLanPortByMeType-> *portId=0x%02x",*portId);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "\r\n getLanPortByMeType-> *portFlag=0x%02x",*portFlag);
#endif
	if(ret != 0){
		ret = -1;
	}
	return ret;	
}

/*******************************************************************************************
**function name
	setMOPMulticastByPort
**description:
	set multicast parameter according to 9.3.27 instance.
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	instId :	9.3.27 multicast operations profile instance id
  	port: 	lan port id
  	type: 
  		bit	description
  		0	version
  		1	function 
  		2	fast leave
  		3	upstream tci
  		4	tag ctrl
  		5	max rate
  		6	dynamic acl list
  		7 	static acl list
  		9	Robustness
  		10	Querier IP address
  		11 	Query interval
  		12	Query max response time
  		13	Last member query interval
  		14	Unauthorized join request
  		15	Downstream IGMP and TCI

********************************************************************************************/
int setMOPMulticastByPort(uint16_t instanceId, uint16_t port, uint16_t type){
	int ret = -1;
	omciIgmpRuleInfo_t ruleRecordInfo;
	omciIgmpRuleInfo_ptr ruleRecord = &ruleRecordInfo;
	omci_table_attr_t *tableStruct_ptr = NULL;
	uint16_t msciInstanceId = 0;
	uint16_t msciAssMopInstanceID = 0;
	uint16_t mbpcdInstanceId = 0;
	uint16_t mbpcdEqualMsciInstanceId = 0;
	uint8_t mbpcdTpType = 0;
	uint8_t *tmp_ptr = NULL;
	uint16_t 	ctrlField_tmp = 0;
	uint16_t	rowPart = 0;
	uint16_t	rowID = 0;
	uint8_t tempValU8 = 0;
	uint16_t tempValU16 = 0;
	uint32_t tempValU32 = 0;
	uint16_t ruleType = 0;
	int  instCnt=0;
	int16_t i=0;
	int length=0;
	uint16_t * instIdList=NULL;
	char *attributeValuePtr=NULL;
	omci_me_info_t me_info={0};
    omci_me_info_t me_tbl_info={0};
	omci_multicast_op_profile_ptr multicast_op_profile_ptr = NULL;
    omci_multicast_op_profile_ptr multicast_op_profile_tbl_ptr = NULL;
	omci_multicast_subs_cfg_info_ptr multicast_subs_cfg_info_ptr = NULL;
	omci_mac_br_port_cfg_ptr mac_br_port_cfg_ptr=NULL;

	/*we should first find all 9.3.28 instances meId by 9.3.27 meId*/
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instanceId =%d, port=%d, clearType=%d\n",__LINE__, __func__, instanceId, port, type);

	if((type&OMCI_MULTICAST_VER_TYPE)
		|| (type&OMCI_MULTICAST_FUNC_TYPE)
		|| (type&OMCI_MULTICAST_FAST_LEAVE_TYPE)
		|| (type&OMCI_MULTICAST_UP_TCI_TYPE)
		|| (type&OMCI_MULTICAST_TAG_CTRL_TYPE)		
		|| (type&OMCI_MULTICAST_MAX_RATE_TYPE)
		|| (type & OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		|| (type&OMCI_MULTICAST_STATIC_ACL_TYPE)
		|| (type&OMCI_MULTICAST_ROBUSTNESS_TYPE)	
		|| (type&OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)	
		|| (type&OMCI_MULTICAST_QUERY_INTERVAL_TYPE)	
		|| (type&OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE)	
		|| (type&OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE)	
		|| (type&OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)	
		|| (type&OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE)
	){
		//nothing		
	}else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]type =%x\n",__LINE__, __func__, type);
		ret = -1;
		goto end;
	}

	me_info.class_id = OMCI_CLASS_ID_MULTICAST_OPERATE_PROFILE;
	me_info.inst_id = instanceId;
	if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
		 //non-standard me, how to deal with ???
		/*#ifdef TCSUPPORT_OMCI_CTC
				me_p = omciGetMeByClassId(OMCI_CLASS_ID_CTC_EXTENDED_MUTICAST_PROFILE);
				if(me_p ==	NULL){
					ret = -1;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]omciIGMPCofigInfoEntity_p == NULL\n",__LINE__, __func__);
					goto end;
				}
				meInst_p = omciGetInstanceByMeId(me_p , instanceId);
				if(meInst_p == NULL)
				{
					ret = -1;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]meInst_p == NULL\n",__LINE__, __func__);
					goto end;
				}
		#else*/
		 ret = -1;
		 omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]meInst_p == NULL\n",__LINE__, __func__);
		 goto end;
		//#endif
	}
	
	multicast_op_profile_ptr = (omci_multicast_op_profile_ptr)(me_info.attributes);
	if((multicast_op_profile_ptr) == NULL)
	{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s] multicast_op_profile_ptr == NULL\n",__LINE__, __func__);
		goto end;
	}

	if(TCSUPPORT_XPON_IGMP_CHT_VAL)
	{
		if(omci_lib_get_inst_count_by_classid(OMCI_CLASS_ID_MULTICAST_SUBSCRIBER_CFG_INFO,&instCnt) == 0)
		{ 
			instIdList = malloc(sizeof(uint16_t) * instCnt);
			if(omci_lib_get_inst_list_by_classid(OMCI_CLASS_ID_MULTICAST_SUBSCRIBER_CFG_INFO,instIdList,instCnt) <= 0)
			{
			    ret = -1;
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s] omci_lib_get_inst_list_by_classid fail\n",__LINE__, __func__);
				goto end;
			}
			
			for (i=0;i<instCnt;i++ )
			{
				me_info.class_id = OMCI_CLASS_ID_MULTICAST_SUBSCRIBER_CFG_INFO;
				me_info.inst_id = instanceId;
				if(omci_attr_get_all_data_except_table_attr(&me_info) != 0) {
					ret = -1;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s] get multicast subceiber cfg data fail\n",__LINE__, __func__);
					goto end;
				}
				
				multicast_subs_cfg_info_ptr = (omci_multicast_subs_cfg_info_ptr)(me_info.attributes);
				if((multicast_subs_cfg_info_ptr) == NULL)
				{
					ret = -1;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s] multicast_subs_cfg_info_ptr == NULL\n",__LINE__, __func__);
					goto end;
				}

				msciAssMopInstanceID = multicast_subs_cfg_info_ptr->multiOpProPointer;
				if(msciAssMopInstanceID == instanceId)
				{
					mbpcdEqualMsciInstanceId = msciInstanceId;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]setMOPMulticastByPort--break---",__LINE__, __func__);
					break;
				}
			}
			if(instIdList != NULL)
			{
			    free(instIdList);
			    instIdList = NULL;
			}
		}

		if(omci_lib_get_inst_count_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA,&instCnt) == 0)
		{
			instIdList = malloc(sizeof(uint16_t) * instCnt);
			if(omci_lib_get_inst_list_by_classid(OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA,instIdList,instCnt) <= 0)
			{	
			    ret = -1;
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s] omci_lib_get_inst_list_by_classid fail\n",__LINE__, __func__);
				goto end;
			}
			for (i=0;i<instCnt;i++ )
			{
				me_info.class_id = OMCI_CLASS_ID_MAC_BRIDGE_PORT_CON_DATA;
				me_info.inst_id = instanceId;
				if(omci_attr_get_all_data_except_table_attr(&me_info) != 0) {
					ret = -1;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s] get mac bridge port configure data fail\n",__LINE__, __func__);
					goto end;
				}

				mac_br_port_cfg_ptr = (omci_mac_br_port_cfg_ptr)(me_info.attributes);
				if((mac_br_port_cfg_ptr) == NULL)
				{
					ret = -1;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s] mac_br_port_cfg_ptr == NULL\n",__LINE__, __func__);
					goto end;
				}

				mbpcdInstanceId = mac_br_port_cfg_ptr->meId;
				if(mbpcdEqualMsciInstanceId == mbpcdInstanceId)
				{		
					mbpcdTpType = mac_br_port_cfg_ptr->tpType;
					break;
				}
			}
			
			if(instIdList != NULL)
			{
			    free(instIdList);
			    instIdList = NULL;
			}
		}

		if(OMCI_MULTICAST_MBPCD_TP_TYPE_VEIP == mbpcdTpType){
			/*fix veip to xponigmp port index 0*/
			port = XPONIGMP_PORT_VEIP_ID;
		}
	
	}
	
	/*set igmp version by port*/
	if(type & OMCI_MULTICAST_VER_TYPE){
		/*get multicast version from instance*/		
		tempValU8 = multicast_op_profile_ptr->igmpVer;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] igmpVer == %d\n",__LINE__, __func__, tempValU8);
		
		/*set version by port*/
#if 0   /*olt don't really want to configure port version,only ask onu for whelther support this version */
		if(igmpONUSetVer(port, tempValU8) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetVer fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
#endif
	}

	/*set igmp function by port*/
	if(type&OMCI_MULTICAST_FUNC_TYPE){
		tempValU8 = multicast_op_profile_ptr->igmpFunc;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] igmpFunc == %d\n",__LINE__, __func__, tempValU8);

		/*set multicast function by port*/
		if(igmpONUSetFunc(port, tempValU8) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s] igmpONUSetFunc fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
	}

	/*set igmp fast leave by port*/
	if(type&OMCI_MULTICAST_FAST_LEAVE_TYPE){	
		tempValU8 = multicast_op_profile_ptr->immediateLeave;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] immediateLeave == %d\n",__LINE__, __func__, tempValU8);
		
		/*set multicast fast leave by port*/
		if(igmpONUSetFastLeave(port, tempValU8) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetFunc fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
	}

	/*set igmp upstream tci  by port*/
	if(type&OMCI_MULTICAST_UP_TCI_TYPE){	
		tempValU16 = multicast_op_profile_ptr->upIgmpTci;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]upIgmpTci == 0x%x\n",__LINE__, __func__, tempValU16);
		
		/*set multicast upstream tci by port*/
		if(igmpONUSetUpstreamTCI(port, tempValU16) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetUpstreamTCI fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
	}

	/*set igmp tag ctrl type  by port*/
	if(type&OMCI_MULTICAST_TAG_CTRL_TYPE){			
		tempValU8 = multicast_op_profile_ptr->upIgmpTagCtrl;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]upIgmpTagCtrl == 0x%x\n",__LINE__, __func__, tempValU8);
		
		/*set tag ctrl  by port*/
		if(igmpONUSetTagCtrl(port, tempValU8) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetUpstreamTCI fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
	}
	
	/*set max rate by port*/
	if(type&OMCI_MULTICAST_MAX_RATE_TYPE){
		tempValU32 = multicast_op_profile_ptr->upIgmpRate;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]maxRate == 0x%04x\n",__LINE__, __func__, tempValU32);

		/*set maxRate by port*/
		if(igmpONUSetMaxRate(port, tempValU32) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetMaxRate fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
	}

	/*Set dynamic ACL ruleRecord from instance || Set static ACL ruleRecord from instance*/	
	if((type&OMCI_MULTICAST_DYNAMIC_ACL_TYPE) ||(type&OMCI_MULTICAST_STATIC_ACL_TYPE)){
		if(type&OMCI_MULTICAST_DYNAMIC_ACL_TYPE){
			/*get dynamic ACL ruleRecord from instance*/
			me_tbl_info.class_id = OMCI_CLASS_ID_MULTICAST_OPERATE_PROFILE;
			me_tbl_info.inst_id = instanceId;
			me_tbl_info.mask = OMCI_MULTICAST_DYNAMIC_ACL_TYPE;
			if(omci_attr_get_one_table_attr_by_mask(&me_tbl_info) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
				ret = -1;
				goto end;
			}
			multicast_op_profile_tbl_ptr = (omci_multicast_op_profile_ptr)(me_tbl_info.attributes);
			tableStruct_ptr = & multicast_op_profile_tbl_ptr->dynAccessCtrlListTable;
			ruleType = OMCI_MULTICAST_IGMP_RULE_TYPE_DYN;
		} else {
			/*get static ACL ruleRecord from instance*/
			me_tbl_info.class_id = OMCI_CLASS_ID_MULTICAST_OPERATE_PROFILE;
			me_tbl_info.inst_id = instanceId;
			me_tbl_info.mask = OMCI_MULTICAST_STATIC_ACL_TYPE;
			if(omci_attr_get_one_table_attr_by_mask(&me_tbl_info) != 0)
			{
				omcidbgPrintf(OMCI_DEBUG_LEVEL_WARN, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
				ret = -1;
				goto end;
			}
			multicast_op_profile_tbl_ptr = (omci_multicast_op_profile_ptr)(me_tbl_info.attributes);
			tableStruct_ptr = & multicast_op_profile_tbl_ptr->staticAccessCtrlListTable;
			ruleType = OMCI_MULTICAST_IGMP_RULE_TYPE_STATIC;
		}
		
		if(tableStruct_ptr != NULL && tableStruct_ptr->buf != NULL){		
			/*Set dynamic ACL ruleRecord from instance*/	
			length = OMCI_MOP_ACL_TABLE_ENTRY_LENGTH;
			for(tmp_ptr = (uint8_t *)tableStruct_ptr->buf; tmp_ptr != NULL; tmp_ptr += OMCI_MOP_ACL_TABLE_ENTRY_LENGTH)
			{
				ctrlField_tmp = get16(tmp_ptr);
				
				rowPart = ((ctrlField_tmp&OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART_MASK)>>OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART_FILED);
				rowID = (ctrlField_tmp & OMCI_MOP_ACL_TABLE_ENTRY_ROW_ID_988_AMD1_MASK);
				
				memset(ruleRecord, 0, sizeof(omciIgmpRuleInfo_t));
				ruleRecord->rowpartId= rowPart;
				ruleRecord->rowKey = rowID;
				ruleRecord->ruleType = ruleType;
				ruleRecord->gemPortId = get16(tmp_ptr+2);
				ruleRecord->vid = get16(tmp_ptr+4);					
				memcpy(ruleRecord->srcIp,tmp_ptr+6, OMCI_MULTICAST_IPV4_LEN);	
				memcpy(ruleRecord->startDestIp,tmp_ptr+10, OMCI_MULTICAST_IPV4_LEN);
				memcpy(ruleRecord->endDestIp,tmp_ptr+14, OMCI_MULTICAST_IPV4_LEN);
				ruleRecord->imputedBandwidth = get32(tmp_ptr+18);

				omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]ruleRecord rowKey:%d,ruleType:%d,gemPortId:%d,vid:%d,srcIp:0x%x,startDestIp:0x%x,endDestIp:0x%x\n",
						__LINE__, __func__, ruleRecord->rowKey,ruleRecord->ruleType,ruleRecord->gemPortId,ruleRecord->vid, 
						get32(ruleRecord->srcIp), get32(ruleRecord->startDestIp), get32(ruleRecord->endDestIp));

				omci_lib_rdkb_gem_vlan_op(ruleRecord->gemPortId,RDKB_GEM_TYPE_MCAST,ruleRecord->vid,RDKB_GEM_VLAN_OP_ADD);
				
				/*set acl rule by port*/
				ret = igmpONUSetDyCtrList(port, (igmpRuleInfo_Ptr)ruleRecord);
				if(ret != 0){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetDyCtrList fail\n",__LINE__, __func__);
				}
				
				length += OMCI_MOP_ACL_TABLE_ENTRY_LENGTH;
				if(length > tableStruct_ptr->len){
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]length:%d > tableStruct_ptr->len:%d",__LINE__, __func__,length, tableStruct_ptr->len);
					break;
				}
			}
		}
	}

	/*set igmp robustness type by port*/
	if(type&OMCI_MULTICAST_ROBUSTNESS_TYPE){		
		tempValU8 = multicast_op_profile_ptr->robustness;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]robustness == %d\n",__LINE__, __func__, tempValU8);

#ifdef TCSUPPORT_XPON_IGMP
		if(igmpONUSetRobustness(port,tempValU8) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetRobustness fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
#endif
	}

	/*set igmp query ip type by port*/
	if(type&OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE){
		char queryip[16] = {0};
		attributeValuePtr = multicast_op_profile_ptr->querierIpAddr;		
		memcpy(queryip, attributeValuePtr, 4);
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]queryip == %d.%d.%d.%d\n",__LINE__, __func__, *attributeValuePtr,*(attributeValuePtr+1),*(attributeValuePtr+2),*(attributeValuePtr+3));

#ifdef TCSUPPORT_XPON_IGMP	
		if(igmpONUSetQueryIp(port,(uint8_t *)queryip) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetRobustness fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
#endif		
	}
	
	/*set igmp query interval type by port*/
	if(type&OMCI_MULTICAST_QUERY_INTERVAL_TYPE){	
		tempValU32 = multicast_op_profile_ptr->queryInterval;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]queryInterval == %d\n",__LINE__, __func__, tempValU32);
#ifdef TCSUPPORT_XPON_IGMP	
		if(igmpONUSetQueryInterval(port,tempValU32) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetQueryInterval fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
#endif

	}
	
	/*set max response time type by port*/		
	if(type&OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE){		
		tempValU32 = multicast_op_profile_ptr->queryMaxRespTime;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]queryMaxRespTime == %d\n",__LINE__, __func__, tempValU32);
#ifdef TCSUPPORT_XPON_IGMP		
		if(igmpONUSetQueryMaxRespTime(port,tempValU32) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetQueryMaxRespTime fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
#endif
	}
	
	/*set last query interval type by port*/
	if(type&OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE){	
		tempValU32 = multicast_op_profile_ptr->lastMemberQueryInterval;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] lastMemberQueryInterval == %d\n",__LINE__, __func__, tempValU32);
#ifdef TCSUPPORT_XPON_IGMP	
		if(igmpONUSetLastQueryInterval(port,tempValU32) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetLastQueryInterval fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
#endif
	}
	
	/*set Unauthorized join request type by port*/ 
	if(type&OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE){		
		tempValU8 = multicast_op_profile_ptr->unAuthJoinReqBehaviour;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]unAuthJoinReqBehaviour == %d\n",__LINE__, __func__, tempValU8);
		
#ifdef TCSUPPORT_XPON_IGMP	
		if(igmpONUSetUnauthorized(port,tempValU8) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetLastQueryInterval fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
#endif
	}
	
	/*set Downstream IGMP and TCI type by port*/
	if(type&OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE){	
		tempValU8 = (uint8_t) (multicast_op_profile_ptr->downIgmpMultiTci[0]);
		tempValU16 = get16((uint8_t*)(& multicast_op_profile_ptr->downIgmpMultiTci[1]));
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]downIgmpMultiTci[0] == %d, downIgmpMultiTci[1][2] == 0x%x\n",__LINE__, __func__, tempValU8, tempValU16);
#ifdef TCSUPPORT_XPON_IGMP		
		if(igmpONUSetDownTCIType(port,tempValU8, tempValU16) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetDownTCIType fail\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
#endif
	}

	ret = 0;
end:
	if(ret != 0){
		ret = -1;
	}
	if(instIdList != NULL)
	{
	    free(instIdList);
		instIdList = NULL;
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret =%x\n",__LINE__, __func__, ret);
	return ret;	
}

/*******************************************************************************************
**function name
	setRealMulticastRuleByMeType
**description:
	set multicast rule according to 9.3.28 me type
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	instId :	9.3.28 multicast subscriber config info ME or 9.3.4 mac bridge port ME  instance id
  	meType: 	
  		0:	9.3.28 me type attribute, pointer to 9.3.4 mac bridge port config data ME
  		1:	9.3.28 me type attribute, pointer to 9.3.10 802.1p ME
  	type: 
  		bit	description
  		0	version
  		1	function 
  		2	fast leave
  		3	upstream tci
  		4	tag ctrl
  		5	max rate
  		6	dynamic acl list
  		7 	static acl list
  		9	Robustness
  		10	Querier IP address
  		11 	Query interval
  		12	Query max response time
  		13	Last member query interval
  		14	Unauthorized join request
  		15	Downstream IGMP and TCI

********************************************************************************************/
static int setRealMulticastRuleByMeType(uint16_t instanceId, uint8_t meType, uint16_t type, uint16_t multiOpProId){
	int ret = -1;
	uint8_t portFlag = 0;
	uint16_t portId = 0;	
	int i = 0;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instanceId =%d, meType=%d, clearType=%d\n",__LINE__, __func__, instanceId, meType, type);
	if((meType == OMCI_MULTICAST_CONFIG_INFO_ME_TYPE_0)
		|| (meType == OMCI_MULTICAST_CONFIG_INFO_ME_TYPE_1)){
		//nothing
	}else{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]meType fail\n",__LINE__, __func__);
		goto end;
	}

	if((type & OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		|| (type&OMCI_MULTICAST_STATIC_ACL_TYPE)
		|| (type&OMCI_MULTICAST_MAX_RATE_TYPE)
		|| (type&OMCI_MULTICAST_VER_TYPE)
		|| (type&OMCI_MULTICAST_FUNC_TYPE)
		|| (type&OMCI_MULTICAST_FAST_LEAVE_TYPE)
		|| (type&OMCI_MULTICAST_UP_TCI_TYPE)
		|| (type&OMCI_MULTICAST_TAG_CTRL_TYPE)		
		|| (type&OMCI_MULTICAST_ROBUSTNESS_TYPE)	
		|| (type&OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)	
		|| (type&OMCI_MULTICAST_QUERY_INTERVAL_TYPE)	
		|| (type&OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE)	
		|| (type&OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE)	
		|| (type&OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)	
		|| (type&OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE)
	){
		//nothing
	}else{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]type fail, \n",__LINE__, __func__);
		goto end;
	}

	/*get lan  port information*/
	ret = getLanPortByMeType(instanceId, meType, &portFlag, &portId);
	if(ret != 0){
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]getLanPortByMeType fail \n",__LINE__, __func__);
		goto end;
	}

	/*real set multicast rule*/
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG){
		ret = setMOPMulticastByPort(multiOpProId, portId, type);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastByPort fail portId = %d\n",__LINE__, __func__, portId);
		}		
	}else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG){
		for(i = 1; i<= MAX_ETH_PORT_NUM; i++){
			portId = i;
			ret = setMOPMulticastByPort(multiOpProId, portId, type);
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastByPort fail portId = %d\n",__LINE__, __func__, portId);
			}
		}
			
	}else{
		//nothing
	}

	ret = 0;
end:
	if(ret != 0){
		ret = -1;
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret =%d\n",__LINE__, __func__, ret);

	return ret;
}

/*******************************************************************************************
**function name
	clearRealMulticastRuleByMeType
**description:
	clear real multicast  rule according 9.3.28 MeType attribute.
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	instanceId :	9.3.28 multicast subscriber config info ME or 9.3.4 mac bridge port config data ME  instance id
  	meType:	9.3.28 meType value
  	clearType: 
  		bit	description
  		0	version
  		1	function 
  		2	fast leave
  		3	upstream tci
  		4	tag ctrl
  		5	max rate
  		6	dynamic acl list
  		7 	static acl list
  		9	Robustness
  		10	Querier IP address
  		11 	Query interval
  		12	Query max response time
  		13	Last member query interval
  		14	Unauthorized join request
  		15	Downstream IGMP and TCI

 ********************************************************************************************/

static int clearRealMulticastRuleByMeType(uint16_t instanceId, uint8_t meType, uint16_t clearType){
	int ret = -1;
	uint8_t portFlag = 0;
	uint16_t portId = 0;	
	int i = 0;
	uint8_t tempPortNum = 0;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instanceId =%d, meType=%d, clearType=%d\n",__LINE__, __func__, instanceId, meType, clearType);
	if((meType == OMCI_MULTICAST_CONFIG_INFO_ME_TYPE_0)
		|| (meType == OMCI_MULTICAST_CONFIG_INFO_ME_TYPE_1)){
		//nothing
	}else{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]meType fail\n",__LINE__, __func__);
		goto end;
	}

	if((clearType&OMCI_MULTICAST_VER_TYPE)
		|| (clearType&OMCI_MULTICAST_FUNC_TYPE)
		|| (clearType&OMCI_MULTICAST_FAST_LEAVE_TYPE)
		|| (clearType&OMCI_MULTICAST_UP_TCI_TYPE)
		|| (clearType&OMCI_MULTICAST_TAG_CTRL_TYPE)
		|| (clearType&OMCI_MULTICAST_MAX_RATE_TYPE)	
		|| (clearType&OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		|| (clearType&OMCI_MULTICAST_STATIC_ACL_TYPE)
		|| (clearType&OMCI_MULTICAST_ROBUSTNESS_TYPE)	
		|| (clearType&OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)	
		|| (clearType&OMCI_MULTICAST_QUERY_INTERVAL_TYPE)	
		|| (clearType&OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE)	
		|| (clearType&OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE)	
		|| (clearType&OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)	
		|| (clearType&OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE)
	){
		//nothing
	}else{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]clearType fail\n",__LINE__, __func__);
		goto end;
	}

	/*get lan  port information*/
	if(getLanPortByMeType(instanceId, meType, &portFlag, &portId) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]getLanPortByMeType fail\n",__LINE__, __func__);
		ret = 0;
		goto end;
	}
	
	/*real clear acl rule*/
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG){
		tempPortNum = 1;		
	}else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG){
		tempPortNum = MAX_ETH_PORT_NUM;
	}else{
		//nothing
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]portFlag fail, portFlag =%d\n",__LINE__, __func__, portFlag);
		ret = -1;
		goto end;
	}
	/*call clean multicast API*/
	for(i = 1; i<= tempPortNum; i++){
		if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG){ // clear all LAN Port CFG
			portId = i; //igmp valid value (1~N)
		}

#ifdef TCSUPPORT_XPON_IGMP
		/*set igmp version to igmp version 2*/
		if(clearType&OMCI_MULTICAST_VER_TYPE){
			if(igmpONUSetVer(portId,OMCI_MULTICAST_VERSION_MLD_V2) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetVer fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set igmp function to snooping*/
		if(clearType&OMCI_MULTICAST_FUNC_TYPE){
			if(igmpONUSetFunc(portId,OMCI_MULTICAST_DEFAULT_MODE) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetFunc fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set igmp disable fast leave*/
		if(clearType&OMCI_MULTICAST_FAST_LEAVE_TYPE){
			if(igmpONUSetFastLeave(portId,OMCI_MULTICAST_DEFAULT_FAST_LEAVE) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetFastLeave fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set igmp upstream TCI to 0*/
		if(clearType&OMCI_MULTICAST_UP_TCI_TYPE){
			if(igmpONUSetUpstreamTCI(portId,OMCI_MULTICAST_DEFAULT_UP_TCI) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetUpstreamTCI fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set igmp upstream tag ctrl to transparent*/
		if(clearType&OMCI_MULTICAST_TAG_CTRL_TYPE){
			if(igmpONUSetTagCtrl(portId,OMCI_MULTICAST_TAG_CTRL_TRANSPARENT) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetTagCtrl fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*clear max rate limit according to the port id*/
		if(clearType&OMCI_MULTICAST_MAX_RATE_TYPE){
			if(igmpONUClearMaxRate(portId) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUClearMaxRate fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*clean dynamic acl */
		if(clearType&OMCI_MULTICAST_DYNAMIC_ACL_TYPE){
			omci_lib_rdkb_gem_vlan_op(0,RDKB_GEM_TYPE_MCAST,0,RDKB_GEM_VLAN_OP_CLEAR);
			if(igmpONUClearDyCtrList(portId) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUClearDyCtrList fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}						
		}
		/*clean static  acl */
		if(clearType&OMCI_MULTICAST_STATIC_ACL_TYPE){
			omci_lib_rdkb_gem_vlan_op(0,RDKB_GEM_TYPE_MCAST,0,RDKB_GEM_VLAN_OP_CLEAR);
			if(igmpONUClearStaticCtrList(portId) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUClearStaticCtrList fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}					
		/*set igmp robustness to default 0*/
		if(clearType&OMCI_MULTICAST_ROBUSTNESS_TYPE){
			if(igmpONUSetRobustness(portId,OMCI_MULTICAST_DEFAULT_ROBUSTNESS) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetRobustness fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set igmp query ip to default 0.0.0.0*/
		if(clearType&OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE){
			uint8_t queryip[16] = {0};
			if(igmpONUSetQueryIp(portId,queryip) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetQueryIp fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set igmp query interval to default 125s*/
		if(clearType&OMCI_MULTICAST_QUERY_INTERVAL_TYPE){
			if(igmpONUSetQueryInterval(portId,OMCI_MULTICAST_DEFAULT_QUERY_INTERVAL) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetQueryInterval fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set max response time to default 100s*/		
		if(clearType&OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE){
			if(igmpONUSetQueryMaxRespTime(portId,OMCI_MULTICAST_DEFAULT_QUERY_MAX_RESPONSE) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetQueryMaxRespTime fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set last query interval to default 10s*/
		if(clearType&OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE){
			if(igmpONUSetLastQueryInterval(portId,OMCI_MULTICAST_DEFAULT_LAST_QUERY_INTERVAL) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetLastQueryInterval fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set Unauthorized join request to default disable*/ 
		if(clearType&OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE){
			if(igmpONUSetUnauthorized(portId,OMCI_MULTICAST_UNAUTHORIZED_JOIN_DISABLE) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetUnauthorized fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
		/*set Downstream IGMP and TCI to default transparent*/
		if(clearType&OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE){
			if(igmpONUSetDownTCIType(portId,OMCI_MULTICAST_DOWN_TAG_CTRL_TRANSPARENT, 0) != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetDownTCIType fail, portId=%d\n",__LINE__, __func__, portId);
				ret = -1;
				goto end;
			}
		}
#endif
	}	

	ret = 0;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret =%d\n",__LINE__, __func__, ret);
	if(ret != 0){
		ret = -1;
	}
	return ret;
}


/*******************************************************************************************
**function name
	clearRealMulticastRuleByProfileType
**description:
	clear multicast  ACL list according to multicast profile and type value
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	currInstId :	9.3.27 multicast operations profile instance id
  	clearType:   		
  		bit	description
  		0	version
  		1	function 
  		2	fast leave
  		3	upstream tci
  		4	tag ctrl
  		5	max rate
  		6	dynamic acl list
  		7 	static acl list
  		9	Robustness
  		10	Querier IP address
  		11 	Query interval
  		12	Query max response time
  		13	Last member query interval
  		14	Unauthorized join request
  		15	Downstream IGMP and TCI
********************************************************************************************/

int clearRealMulticastRuleByProfileType(IN uint16_t currInstId, IN uint16_t clearType){
	int ret = -1;
	uint16_t tempInstId = 0;
	uint16_t tempMulticastProfileInstId = 0;
	uint8_t tempMeType = 0;
	uint16_t inst_id_array[MAX_INST_COUNT]={0};
	int inst_count = 0, i = 0, j=0;
	omci_me_info_t me_info = {0};
	omci_multicast_subs_cfg_info_ptr multi_subs_cfg_info_attr = NULL;
	omci_table_attr_ptr mcastSrvPktTbl_p = NULL;


	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, currInstId =%d, type=%d\n",__LINE__, __func__, currInstId, clearType);

	if((clearType&OMCI_MULTICAST_VER_TYPE)
		|| (clearType&OMCI_MULTICAST_FUNC_TYPE)
		|| (clearType&OMCI_MULTICAST_FAST_LEAVE_TYPE)
		|| (clearType&OMCI_MULTICAST_UP_TCI_TYPE)
		|| (clearType&OMCI_MULTICAST_TAG_CTRL_TYPE)
		|| (clearType&OMCI_MULTICAST_MAX_RATE_TYPE)	
		|| (clearType&OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		|| (clearType&OMCI_MULTICAST_STATIC_ACL_TYPE)
		|| (clearType&OMCI_MULTICAST_ROBUSTNESS_TYPE)	
		|| (clearType&OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)	
		|| (clearType&OMCI_MULTICAST_QUERY_INTERVAL_TYPE)	
		|| (clearType&OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE)	
		|| (clearType&OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE)	
		|| (clearType&OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)	
		|| (clearType&OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE)
	){
		//nothing		
	}else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]type fail, type=%d\n",__LINE__, __func__, clearType);
		ret = -1;
		goto end;
	}
		
	me_info.class_id = OMCI_CLASS_ID_MULTICAST_SUBSCRIBER_CFG_INFO;
	if(omci_lib_get_inst_count_by_classid(me_info.class_id, &inst_count) == -1){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_count_by_classid failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	if(omci_lib_get_inst_list_by_classid(me_info.class_id, inst_id_array, inst_count) == -1){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_list_by_classid failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	for(j = 0; j < inst_count; j++){
		/*3.1 get 9.3.28 instance id*/
		me_info.inst_id = inst_id_array[j];
		if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]get data failed.\n",__LINE__,__FUNCTION__);
			continue;
		}
		
		multi_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info.attributes;
		if(NULL == multi_subs_cfg_info_attr){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s] attributes is NULL!\n",__LINE__,__FUNCTION__);
			continue;
		}
		tempInstId = me_info.inst_id; //9.3.28 inst id
		tempMeType = multi_subs_cfg_info_attr->meType; //9.3.28 ME type attribute
		tempMulticastProfileInstId = multi_subs_cfg_info_attr->multiOpProPointer; //9.3.28 multicast operations profile pointer attribute

		if(tempMulticastProfileInstId == 0 || tempMulticastProfileInstId == 0xffff){
			me_info.mask = OMCI_MULTICAST_SERVICE_PACKAGE_TAB_MASK; //set mask for table attrite
			if(omci_attr_get_one_table_attr_by_mask(&me_info) != 0)
			{
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
				continue;
			}
			multi_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info.attributes;
			mcastSrvPktTbl_p = & multi_subs_cfg_info_attr->multiSrvPackTable;
			if(mcastSrvPktTbl_p != NULL){
				for(i=0; i< mcastSrvPktTbl_p->len/MCAST_SRV_PKT_TBL_LEN; i++){
					tempMulticastProfileInstId = get16((uint8_t *)&mcastSrvPktTbl_p->buf[MCAST_OP_PROF_OFFSET + i*MCAST_SRV_PKT_TBL_LEN]); //Multicast Service package table
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] multiSrvPktTblPointer=%d\n",__FUNCTION__,__LINE__,tempMulticastProfileInstId);
					if(tempMulticastProfileInstId == currInstId)
						break;
				}
			}
		}

		if(tempMulticastProfileInstId == currInstId){			
			ret = clearRealMulticastRuleByMeType(tempInstId, tempMeType, clearType);			
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]clearRealMulticastRuleByMeType fail\n",__LINE__, __func__);
				ret = -1;
				goto end;
			}			
		}
	}
	
	ret = 0;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret =%d\n",__LINE__, __func__, ret);
	return ret;
}


/*******************************************************************************************
**function name
	setRealMulticastRuleByProfile
**description:
	set multicast value by calling multicast API
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	currInstId :	9.3.27 multicast operations profile instance id
  	type: 
  		bit	description
  		0	version
  		1	function 
  		2	fast leave
  		3	upstream tci
  		4	tag ctrl
  		5	max rate
  		6	dynamic acl list
  		7 	static acl list
  		9	Robustness
  		10	Querier IP address
  		11 	Query interval
  		12	Query max response time
  		13	Last member query interval
  		14	Unauthorized join request
  		15	Downstream IGMP and TCI


  	aclRuleAction: acl rule action type, 1:add a rule, 2:delete a rule according to the ruleRecord->rowkey
  	val_ptr: max rate or version or function type, fast leave type, upstream tci type, tag ctrl type value
  	ruleRecord: igmp rule value
********************************************************************************************/
int setRealMulticastRuleByProfile(IN uint16_t currInstId, IN uint16_t type, IN uint8_t aclRuleAction, IN char *val_ptr, IN omciIgmpRuleInfo_t *ruleRecord){
	int ret = -1;
	uint16_t tempInstId = 0;
	uint16_t tempMulticastProfileInstId = 0;
	uint8_t tempMeType = 0;
	int i = 0, j = 0;
	uint16_t portId = 0;
	uint8_t opFlag = 0;
	uint8_t tempValU8 = 0;
	uint16_t tempValU16 = 0;
	uint32_t tempValU32 = 0;
	uint8_t maxPortNum = 0;
	uint16_t inst_id_array[MAX_INST_COUNT]={0};
	int inst_count = 0;
	omci_me_info_t me_info = {0};
	omci_multicast_subs_cfg_info_ptr multi_subs_cfg_info_attr = NULL;
	omci_table_attr_ptr mcastSrvPktTbl_p = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, currInstId =%d, type=%x\n",__LINE__, __func__, currInstId, type);

	if((type & OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		|| (type&OMCI_MULTICAST_STATIC_ACL_TYPE)
		|| (type&OMCI_MULTICAST_MAX_RATE_TYPE)
		|| (type&OMCI_MULTICAST_VER_TYPE)
		|| (type&OMCI_MULTICAST_FUNC_TYPE)
		|| (type&OMCI_MULTICAST_FAST_LEAVE_TYPE)
		|| (type&OMCI_MULTICAST_UP_TCI_TYPE)
		|| (type&OMCI_MULTICAST_TAG_CTRL_TYPE)		
		|| (type&OMCI_MULTICAST_ROBUSTNESS_TYPE)	
		|| (type&OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)	
		|| (type&OMCI_MULTICAST_QUERY_INTERVAL_TYPE)	
		|| (type&OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE)	
		|| (type&OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE)	
		|| (type&OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)	
		|| (type&OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE)
	){
		//nothing		
	}else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]type fail type = %x\n",__LINE__, __func__, type);
		ret = -1;
		goto end;
	}

	if((type&OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		|| (type&OMCI_MULTICAST_STATIC_ACL_TYPE)){
		if(ruleRecord == NULL){
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]ruleRecord= NULL\n",__LINE__, __func__);
			goto end;
		}

		if((aclRuleAction == OMCI_IGMP_ACL_TABLE_ENTRY_WRITE_ACTION)
			|| (aclRuleAction == OMCI_IGMP_ACL_TABLE_ENTRY_DEL_ACTION)){
			//nothing
		}else{
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]aclRuleAction = %x\n",__LINE__, __func__, aclRuleAction);
			goto end;
		}
	}else{
		if(val_ptr == NULL){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]val_ptr = NULL\n",__LINE__, __func__);
			ret = -1;
			goto end;
		}
	}
	
	me_info.class_id = OMCI_CLASS_ID_MULTICAST_SUBSCRIBER_CFG_INFO;
	if(omci_lib_get_inst_count_by_classid(me_info.class_id, &inst_count) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_count_by_classid failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	if(omci_lib_get_inst_list_by_classid(me_info.class_id, inst_id_array, inst_count) == -1){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]omci_lib_get_inst_list_by_classid failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	
	for(j = 0; j < inst_count; j++){
		/*3.1 get 9.3.28 instance id*/
		me_info.inst_id = inst_id_array[j];
		if(omci_attr_get_all_data_except_table_attr(&me_info) != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
			continue;
		}
		
		multi_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info.attributes;
		if(NULL == multi_subs_cfg_info_attr){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "%s->multi_subs_cfg_info_attr fail\n",__FUNCTION__);
			continue;
		}
		tempInstId = me_info.inst_id; //9.3.28 inst id
		tempMeType = multi_subs_cfg_info_attr->meType; //9.3.28 ME type attribute
		me_info.mask = OMCI_MULTICAST_SERVICE_PACKAGE_TAB_MASK; //set mask for table attrite
		if(omci_attr_get_one_table_attr_by_mask(&me_info) == 0)
		{
			multi_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info.attributes;			
			mcastSrvPktTbl_p = & multi_subs_cfg_info_attr->multiSrvPackTable;
			if(mcastSrvPktTbl_p != NULL && mcastSrvPktTbl_p->len >= MCAST_SRV_PKT_TBL_LEN){
				for(i=0; i< mcastSrvPktTbl_p->len/MCAST_SRV_PKT_TBL_LEN; i++){
						tempMulticastProfileInstId = get16((uint8_t *)&mcastSrvPktTbl_p->buf[MCAST_OP_PROF_OFFSET + i*MCAST_SRV_PKT_TBL_LEN]); //Multicast Service package table
						omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] multiSrvPktTblPointer=%d\n",__FUNCTION__,__LINE__,tempMulticastProfileInstId);
						if(tempMulticastProfileInstId == currInstId){
							break;
						}
				}
			}else{
				tempMulticastProfileInstId = multi_subs_cfg_info_attr->multiOpProPointer; //9.3.28 multicast operations profile pointer attribute 
			}
		}else{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: get attribute fail.\n",__FILE__, __LINE__);
			tempMulticastProfileInstId = multi_subs_cfg_info_attr->multiOpProPointer; //9.3.28 multicast operations profile pointer attribute 
		}
				
		if(tempMulticastProfileInstId == currInstId){
			/*get lan  port information*/
			ret = getLanPortByMeType(tempInstId, tempMeType, &opFlag, &portId);
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]getLanPortByMeType fail\n",__LINE__, __func__);
				continue;
			} 

			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] inst=0x%x, portId=%d, type=0x%x\n",__LINE__, __func__, currInstId, portId, type);

			/*CALL multicast API*/
			if(opFlag == OMCI_MULTICAST_ONE_PORT_FLAG){
				maxPortNum = 1;				
			}else if(opFlag == OMCI_MULTICAST_ALL_PORT_FLAG){
				maxPortNum = MAX_ETH_PORT_NUM;
			}else{
				//nothing
				omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]opFlag = %x\n",__LINE__, __func__, opFlag);
				continue;
			}
			for(i = 1; i<= maxPortNum; i++){
				if(opFlag == OMCI_MULTICAST_ALL_PORT_FLAG){
					portId = i; //igmp valid value (1~N)
				}
		
				if(type&OMCI_MULTICAST_VER_TYPE){
					tempValU8= *(uint8_t *)val_ptr;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU8 == %x\n",__LINE__, __func__, tempValU8);
#if 0  /*olt don't really want to configure port version,only ask onu for whelther support this version */
					ret = igmpONUSetVer(portId, tempValU8);
					if(ret != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetVer fail\n",__LINE__, __func__);
					}
#endif
				}
				if(type&OMCI_MULTICAST_FUNC_TYPE){
					tempValU8= *(uint8_t *)val_ptr;

					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU8 == %x\n",__LINE__, __func__, tempValU8);
					ret = igmpONUSetFunc(portId, tempValU8);
					if(ret != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetFunc fail\n",__LINE__, __func__);
					}
				}
				if(type&OMCI_MULTICAST_FAST_LEAVE_TYPE){
					tempValU8= *(uint8_t *)val_ptr;
					
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU8 == %x\n",__LINE__, __func__, tempValU8);
					ret = igmpONUSetFastLeave(portId, tempValU8);
					if(ret != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetFastLeave fail\n",__LINE__, __func__);
					}
				}
				if(type&OMCI_MULTICAST_UP_TCI_TYPE){
					tempValU16= *(uint16_t *)val_ptr;
					
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU16 == %x\n",__LINE__, __func__, tempValU16);
					ret = igmpONUSetUpstreamTCI(portId, tempValU16);
					if(ret != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetUpstreamTCI fail\n",__LINE__, __func__);
					}
				}
				if(type&OMCI_MULTICAST_TAG_CTRL_TYPE){
					tempValU8= *(uint8_t *)val_ptr;
					
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU16 == %x\n",__LINE__, __func__, tempValU8);
					ret = igmpONUSetTagCtrl(portId, tempValU8);
					if(ret != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetTagCtrl fail\n",__LINE__, __func__);
					}
				}
				if(type&OMCI_MULTICAST_MAX_RATE_TYPE){
					tempValU32 = *(uint32_t *)val_ptr;
					
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU32 == %x\n",__LINE__, __func__, tempValU32);
					ret = igmpONUSetMaxRate(portId, tempValU32);
					if(ret != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetMaxRate fail\n",__LINE__, __func__);
					}
				}
				if((type&OMCI_MULTICAST_DYNAMIC_ACL_TYPE) || (type&OMCI_MULTICAST_STATIC_ACL_TYPE)){		
					switch(aclRuleAction){
						case OMCI_IGMP_ACL_TABLE_ENTRY_WRITE_ACTION: //add acl rule
							if(type&OMCI_MULTICAST_DYNAMIC_ACL_TYPE){
								omci_lib_rdkb_gem_vlan_op(ruleRecord->gemPortId,RDKB_GEM_TYPE_MCAST,ruleRecord->vid,RDKB_GEM_VLAN_OP_ADD);
								ret = igmpONUSetDyCtrList(portId, (igmpRuleInfo_Ptr)ruleRecord);
								if(ret != 0){
										omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetDyCtrList  fail,tempInstId=0x%02x,portId=%d\n",__LINE__, __func__, tempInstId, portId);
								}
							}
							if(type&OMCI_MULTICAST_STATIC_ACL_TYPE){
								omci_lib_rdkb_gem_vlan_op(ruleRecord->gemPortId,RDKB_GEM_TYPE_MCAST,ruleRecord->vid,RDKB_GEM_VLAN_OP_ADD);
								ret = igmpONUSetStaticCtrList(portId, (igmpRuleInfo_Ptr)ruleRecord);
								if(ret != 0){
										omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetStaticCtrList  fail,tempInstId=0x%02x,portId=%d\n",__LINE__, __func__, tempInstId, portId);
								}
							}
							break;

						case OMCI_IGMP_ACL_TABLE_ENTRY_DEL_ACTION://del acl rule
							if(type&OMCI_MULTICAST_DYNAMIC_ACL_TYPE){
								omci_lib_rdkb_gem_vlan_op(ruleRecord->gemPortId,RDKB_GEM_TYPE_MCAST,ruleRecord->vid,RDKB_GEM_VLAN_OP_REMOVE);
								ret = igmpONUDelDyCtrList(portId, ruleRecord->rowKey);
								if(ret != 0){
										omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]->igmpONUDelDyCtrList  fail,tempInstId=0x%02x,portId=%d",__LINE__, __func__,tempInstId, portId);
								}
							}
							if(type&OMCI_MULTICAST_STATIC_ACL_TYPE){
								omci_lib_rdkb_gem_vlan_op(ruleRecord->gemPortId,RDKB_GEM_TYPE_MCAST,ruleRecord->vid,RDKB_GEM_VLAN_OP_REMOVE);
								ret = igmpONUDelStaticCtrList(portId, ruleRecord->rowKey);
								if(ret != 0){
										omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]->igmpONUDelStaticCtrList  fail,tempInstId=0x%02x,portId=%d",__LINE__, __func__,tempInstId, portId);
								}
							}
							break;
							
						default:
							break;
					}
				}
#ifdef TCSUPPORT_XPON_IGMP					
				/*set igmp robustness type by port*/
				if(type&OMCI_MULTICAST_ROBUSTNESS_TYPE){
					tempValU8 = *(uint8_t *)val_ptr;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU8 == %x\n",__LINE__, __func__, tempValU8);
				
					if(igmpONUSetRobustness(portId,tempValU8) != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetRobustness fail\n",__LINE__, __func__);
						ret = -1;
						goto end;
					}
				}
				
				/*set igmp query ip type by port*/
				if(type&OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE){
					tempValU8 = *(uint8_t *)val_ptr;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU8 == %02x%02x%02x%02x\n",__LINE__, __func__, *val_ptr,*(val_ptr+1),*(val_ptr+2),*(val_ptr+3));
				
					if(igmpONUSetQueryIp(portId,(uint8_t *)val_ptr) != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetRobustness fail\n",__LINE__, __func__);
						ret = -1;
						goto end;
					}
				}
				
				/*set igmp query interval type by port*/
				if(type&OMCI_MULTICAST_QUERY_INTERVAL_TYPE){
					tempValU32 = *(uint32_t*)val_ptr;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU32 == %x\n",__LINE__, __func__, tempValU32);
				
					if(igmpONUSetQueryInterval(portId,tempValU32) != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetQueryInterval fail\n",__LINE__, __func__);
						ret = -1;
						goto end;
					}
				}
				
				/*set max response time type by port*/		
				if(type&OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE){
					tempValU32 = *(uint32_t*)val_ptr;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU32 == %x\n",__LINE__, __func__, tempValU32);
				
					if(igmpONUSetQueryMaxRespTime(portId,tempValU32) != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetQueryMaxRespTime fail\n",__LINE__, __func__);
						ret = -1;
						goto end;
					}
				}
				
				/*set last query interval type by port*/
				if(type&OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE){
					tempValU32 = *(uint32_t*)val_ptr;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU32 == %x\n",__LINE__, __func__, tempValU32);
				
					if(igmpONUSetLastQueryInterval(portId,tempValU32) != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetLastQueryInterval fail\n",__LINE__, __func__);
						ret = -1;
						goto end;
					}
				}
				
				/*set Unauthorized join request type by port*/ 
				if(type&OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE){
					tempValU8 = *(uint8_t *)val_ptr;
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU8 == %x\n",__LINE__, __func__, tempValU8);
				
					if(igmpONUSetUnauthorized(portId,tempValU8) != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetLastQueryInterval fail\n",__LINE__, __func__);
						ret = -1;
						goto end;
					}
				}
				
				/*set Downstream IGMP and TCI type by port*/
				if(type&OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE){
					tempValU8 = *val_ptr;
					tempValU16 = get16((uint8_t*)val_ptr+1);
					omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]tempValU8 == %x, tempValU16 == %x\n",__LINE__, __func__, tempValU8, tempValU16);
	
					if(igmpONUSetDownTCIType(portId,tempValU8, tempValU16) != 0){
						omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetDownTCIType fail\n",__LINE__, __func__);
						ret = -1;
						goto end;
					}
				}
#endif					
			}	
		}
	}
	
	ret = 0;	
end:
	if(ret != 0){
		ret = -1;
	}
	return ret;	
}

static int setMOPMulticastAttrValue(uint16_t instId, uint16_t type, char *val_ptr){
	int ret = -1;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x, type=%02x\n",__LINE__, __func__, instId, type);
	if(val_ptr == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]val_ptr == NULL\n",__LINE__, __func__);
		goto end;
	}
	/*clear all configuration in lan port according to the this profile*/
	if(clearRealMulticastRuleByProfileType(instId, type) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]clearRealMulticastRuleByProfileType fail\n",__LINE__, __func__);
		goto end;
	}
	
	/*set multicast rule */
	if(setRealMulticastRuleByProfile(instId, type, 0, val_ptr, NULL) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setRealMulticastRuleByProfile fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}
	
	ret = 0;	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}

/*******************************************************************************************************************************
9.3.27 multicast operations profile

********************************************************************************************************************************/
int setMOPMulticastVersionValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint8_t igmpVersion = 0;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;

	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	type = OMCI_MULTICAST_VER_TYPE;
	igmpVersion = multicast_op_attr->igmpVer;
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x, igmpVersion=%02x\n",__LINE__, __func__, instanceId, igmpVersion);
	
	switch(igmpVersion){
		case OMCI_MULTICAST_VERSION_V2:
		case OMCI_MULTICAST_VERSION_V3:
		case OMCI_MULTICAST_VERSION_MLD_V1:
		case OMCI_MULTICAST_VERSION_MLD_V2:			
			break;
		default:
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpVersion reserved\n",__LINE__, __func__);
			goto end;
	}
	
	if(setMOPMulticastAttrValue(instanceId, type, (char *)&igmpVersion) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
		ret = -1;
		goto end;
	}

	ret = 0;
end:
	return ret;
}


int setMOPMulticastFuncValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint8_t igmpFuncType = 0;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;

	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	type = OMCI_MULTICAST_FUNC_TYPE;
	igmpFuncType = multicast_op_attr->igmpFunc;
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x, igmpFuncType=%02x\n",__LINE__, __func__, instanceId, igmpFuncType);
	
	switch(igmpFuncType){
		case OMCI_MULTICAST_FUNCTION_SNOOPING:
		case OMCI_MULTICAST_FUNCTION_SPR:
		case OMCI_MULTICAST_FUNCTION_PROXY:		
			break;
		default:
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpFuncType not support\n",__LINE__, __func__);
			goto end;
	}
	
	if(setMOPMulticastAttrValue(instanceId, type, (char *)&igmpFuncType) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}

	ret = 0;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}


int setMOPMulticastFastLeaveValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint8_t igmpFastLeave = 0;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;

	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	type = OMCI_MULTICAST_FAST_LEAVE_TYPE;
	igmpFastLeave = multicast_op_attr->immediateLeave;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x, igmpFastLeave=%02x\n",__LINE__, __func__, instanceId, igmpFastLeave);
	
	switch(igmpFastLeave){
		case OMCI_MULTICAST_FAST_LEAVE_DISABLE:
		case OMCI_MULTICAST_FAST_LEAVE_ENABLE:	
			break;
		default:
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpFastLeave not support\n",__LINE__, __func__);
			goto end;
	}

	if(setMOPMulticastAttrValue(instanceId, type, (char *)&igmpFastLeave) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}

	ret = 0;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}

int setMOPMulticastUpstreamTCIValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint16_t upSteamTCI = 0;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;

	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	type = OMCI_MULTICAST_UP_TCI_TYPE;
	upSteamTCI = multicast_op_attr->upIgmpTci;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x, upSteamTCI=%02x\n",__LINE__, __func__, instanceId, upSteamTCI);
	
	if(setMOPMulticastAttrValue(instanceId, type, (char *)&upSteamTCI) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}

	ret = 0;
	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}

int setMOPMulticastTagCtrlValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint8_t tagCtrlVal = 0;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;

	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	type = OMCI_MULTICAST_TAG_CTRL_TYPE;
	tagCtrlVal = multicast_op_attr->upIgmpTagCtrl;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x, tagCtrlVal=%02x\n",__LINE__, __func__, instanceId, tagCtrlVal);
	
	switch(tagCtrlVal){
		case OMCI_MULTICAST_TAG_CTRL_TRANSPARENT:
		case OMCI_MULTICAST_TAG_CTRL_ADD_TCI:
		case OMCI_MULTICAST_TAG_CTRL_REPLACE_TCI:
		case OMCI_MULTICAST_TAG_CTRL_REPLACE_VID:
			break;
		default: //only update instance value
			ret = 0;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpFuncType not support\n",__LINE__, __func__);
			goto end;
	}

	if(setMOPMulticastAttrValue(instanceId, type, (char *)&tagCtrlVal) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
		goto end;
	}	

	ret = 0;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}

int setMOPMulticastUpstreamRateValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = -1;
	uint32_t maxRate = 0;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;

	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	type = OMCI_MULTICAST_MAX_RATE_TYPE;
	maxRate = multicast_op_attr->upIgmpRate;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x, maxRate=%x\n",__LINE__, __func__, instanceId, maxRate);
	
	if(setMOPMulticastAttrValue(instanceId, type, (char *)&maxRate) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
		goto end;
	}
	
	ret = 0;	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}



/*******************************************************************************************
**function name
	setMOPMulticastAclTableValueByType
**description:
	Set ACL Value for OLT request according to the attribute index.
 **retrun :
 	-1:	failure
 	0:	success
**parameter:
  	value :	return value
  	meInstantPtr: 9.3.27 instance pointer
  	omciAttribute: 9.3.27 attribute pointer
  	attrIndex: valid value
  		7: dynamic acl attribute
  		8: static acl attribute
********************************************************************************************/
static int setMOPMulticastAclTableValueByType(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr, IN uint16_t attrIndex){
	uint8_t *tmp_ptr = NULL;
	uint8_t action = 0;//0:remove this entry, 1:add this entry, 2: clear table
	uint16_t instanceId = 0;//instance id
	uint32_t tableSize = 0;
	uint32_t length = 0;
	uint8_t findFlag = 0;//0:not find, 1:find
	int ret = -1;
	uint16_t ctrlField = 0;
	uint8_t setCtrl = 0;
	uint8_t rowPart = 0;
	uint16_t rowID = 0;
	uint16_t ctrlField_tmp = 0;
	uint8_t rowPart_tmp = 0;
	uint16_t rowID_tmp = 0;	
	omciIgmpRuleInfo_t ruleRecordInfo;
	omciIgmpRuleInfo_ptr ruleRecord = &ruleRecordInfo;
	uint16_t type = 0;
	uint16_t ruleType = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;
	omci_me_info_t old_me = {0};
	omci_multicast_op_profile_ptr multicast_op_attr_old = NULL;
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, attrIndex =%02x\n",__LINE__, __func__, attrIndex);

    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get instance id*/
	instanceId = me_info->inst_id;

	/*only support dynamic acl attribute or static acl attribute*/
	if(attrIndex == OMCI_MULTICAST_DYNAMIC_ACL_ATTR_INDEX){
		ruleType = OMCI_MULTICAST_IGMP_RULE_TYPE_DYN;
		type = OMCI_MULTICAST_DYNAMIC_ACL_TYPE;
	}else if(attrIndex == OMCI_MULTICAST_STATIC_ACL_ATTR_INDEX){
		ruleType = OMCI_MULTICAST_IGMP_RULE_TYPE_STATIC;
		type = OMCI_MULTICAST_STATIC_ACL_TYPE;		
	}else{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]attrIndex fail\n",__LINE__, __func__);
		goto end;
	}

	/*parse value*/
	tmp_ptr = (uint8_t *)multicast_op_attr->dynAccessCtrlListTable.buf;
    if(tmp_ptr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] dynAccessCtrlListTable is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	ctrlField = get16(tmp_ptr);
	setCtrl = ((ctrlField&OMCI_MOP_ACL_TABLE_ENTRY_SET_CTRL_MASK)>> OMCI_MOP_ACL_TABLE_ENTRY_SET_CTRL_FILED);
	rowPart = ((ctrlField&OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART_MASK)>> OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART_FILED);
	rowID = (ctrlField & OMCI_MOP_ACL_TABLE_ENTRY_ROW_ID_988_AMD1_MASK);	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]setCtrl=0x%2x, rowPart=0x%2x, rowID=%d\n",__LINE__, __func__, setCtrl,rowPart,rowID);

	/*only support row part0*/
	if(rowPart == OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART0){
		/*set rule from packet value */
		memset(ruleRecord, 0, sizeof(omciIgmpRuleInfo_t));
		ruleRecord->rowpartId = rowPart;
		ruleRecord->rowKey = rowID;
		ruleRecord->ruleType = ruleType;
		ruleRecord->gemPortId = get16(tmp_ptr+2);
		ruleRecord->vid = get16(tmp_ptr+4);
		memcpy(ruleRecord->srcIp,tmp_ptr+6, OMCI_MULTICAST_IPV4_LEN);
		memcpy(ruleRecord->startDestIp,tmp_ptr+10, OMCI_MULTICAST_IPV4_LEN);
		memcpy(ruleRecord->endDestIp,tmp_ptr+14, OMCI_MULTICAST_IPV4_LEN);
		ruleRecord->imputedBandwidth = get32(tmp_ptr+18);
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]ruleRecord rowKey:%x,ruleType:%x,gemPortId:%x,vid:%x,srcIp:%x,startDestIp:%x,endDestIp:%x\n",
				__LINE__, __func__, ruleRecord->rowKey,ruleRecord->ruleType,ruleRecord->gemPortId,ruleRecord->vid, 
			get32(ruleRecord->srcIp), get32(ruleRecord->startDestIp), get32(ruleRecord->endDestIp));	
	} else if(rowPart == OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART1){
		/* we need hanle this table entry to G.988 format(not raw port&&test) */	
		memset(ruleRecord, 0, sizeof(omciIgmpRuleInfo_t));
		ruleRecord->rowpartId = rowPart;
		ruleRecord->rowKey = rowID;
		ruleRecord->ruleType = ruleType;
		memcpy(ruleRecord->srcIp,tmp_ptr+2, OMCI_MULTICAST_IPV4_OFFSET);
		ruleRecord->previewLength = get16(tmp_ptr+14);
		ruleRecord->previewRepeatTime = get16(tmp_ptr+16);
		ruleRecord->previewRepeatCount = get16(tmp_ptr+18);
		ruleRecord->previewResetTime = get16(tmp_ptr+20);		
	} else if(rowPart == OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART2){
		memset(ruleRecord, 0, sizeof(omciIgmpRuleInfo_t));
		ruleRecord->rowpartId = rowPart;
		ruleRecord->rowKey = rowID;
		ruleRecord->ruleType = ruleType;
		memcpy(ruleRecord->startDestIp,tmp_ptr+2, OMCI_MULTICAST_IPV4_OFFSET);
		memcpy(ruleRecord->endDestIp,tmp_ptr+2, OMCI_MULTICAST_IPV4_OFFSET);
	} else{
		goto end;
	}
	/*don't support extend format, so test bit in table contrl will be set to 1.*/
//	ctrlField |= OMCI_MOP_ACL_TABLE_ENTRY_CLEAR_TEST_BIT;
//	put16(tmp_ptr, ctrlField);

	/*get instance id*/
	instanceId = me_info->inst_id;

	old_me.class_id = me_info->class_id;
	old_me.inst_id = me_info->inst_id;
	old_me.mask = OMCI_MULTICAST_DYNAMIC_ACL_TYPE;
	
	if(omci_attr_get_one_table_attr_by_mask(&old_me) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}		
	/*get current setting table entry. */
	multicast_op_attr_old = (omci_multicast_op_profile_ptr)old_me.attributes;  
	if(multicast_op_attr_old == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
		ret = -1;
		goto end;
	}
	/*get current table content*/
	tableSize = multicast_op_attr_old->dynAccessCtrlListTable.len;
	tmp_ptr = (uint8_t *)multicast_op_attr_old->dynAccessCtrlListTable.buf;

	/*get action(add/del/clear)*/
	action = setCtrl;	
	if(action == OMCI_IGMP_ACL_TABLE_ENTRY_DEL_ACTION){// delete table

		/*search record*/
		length = OMCI_MOP_ACL_TABLE_ENTRY_LENGTH;
		while(tmp_ptr != NULL){
			ctrlField_tmp = get16(tmp_ptr);
			rowPart_tmp = ((ctrlField_tmp&OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART_MASK)>> OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART_FILED);
			rowID_tmp = (ctrlField_tmp & OMCI_MOP_ACL_TABLE_ENTRY_ROW_ID_988_AMD1_MASK);
			//if (rowID == rowID_tmp){
			if((rowID == rowID_tmp) &&(rowPart == rowPart_tmp)){
				findFlag = 1; //find
				break;
			}
			
			length += OMCI_MOP_ACL_TABLE_ENTRY_LENGTH;
			if(length > multicast_op_attr_old->dynAccessCtrlListTable.len){ 
				omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]length:%d > multicast_op_attr_old->dynAccessCtrlListTable.len:%d\n",
					__LINE__, __func__, length, multicast_op_attr_old->dynAccessCtrlListTable.len);
				findFlag = 0;//not find
				break;
			}
			tmp_ptr += OMCI_MOP_ACL_TABLE_ENTRY_LENGTH;
		}
		
		/*get real length*/
		length -= OMCI_MOP_ACL_TABLE_ENTRY_LENGTH;
		/*get valid content in table*/
		if(findFlag == 1){
			/*delete ACL rule via calling multicast API*/
			ret = setRealMulticastRuleByProfile(instanceId, type, action, NULL, ruleRecord);
			if(ret != 0){
				ret = -1;
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setRealMulticastRuleByProfile fail\n",__LINE__, __func__);
				goto end;
			}			
			
			/*delete a entry from table list*/			
			/*malloc new space*/
			if(tableSize-OMCI_MOP_ACL_TABLE_ENTRY_LENGTH > 0)
			{
				tableSize -= OMCI_MOP_ACL_TABLE_ENTRY_LENGTH; //update current table size
			}
			else
			{
				tableSize = 0;
			}
		}else{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] not find \n", __LINE__, __func__);			
		}
	}else if(action == OMCI_IGMP_ACL_TABLE_ENTRY_WRITE_ACTION)// add or modify table
	{
		/*search record*/
		for(length = OMCI_MOP_ACL_TABLE_ENTRY_LENGTH; tmp_ptr != NULL; tmp_ptr += OMCI_MOP_ACL_TABLE_ENTRY_LENGTH){		
			ctrlField_tmp = get16(tmp_ptr);
			rowPart_tmp = ((ctrlField_tmp&OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART_MASK)>> OMCI_MOP_ACL_TABLE_ENTRY_ROW_PART_FILED);
			rowID_tmp = (ctrlField_tmp & OMCI_MOP_ACL_TABLE_ENTRY_ROW_ID_988_AMD1_MASK);
			//if (rowID == rowID_tmp){
			if((rowID == rowID_tmp) &&(rowPart == rowPart_tmp)){
				findFlag = 1; //find
				break;
			}

			length += OMCI_MOP_ACL_TABLE_ENTRY_LENGTH;
			if(length > multicast_op_attr_old->dynAccessCtrlListTable.len){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]length:%d > multicast_op_attr_old->dynAccessCtrlListTable.len:%d\n",
					__LINE__, __func__, length, multicast_op_attr_old->dynAccessCtrlListTable.len);
				findFlag = 0;//not find
				break;
			}
		}
		/*get real length*/
		length -= OMCI_MOP_ACL_TABLE_ENTRY_LENGTH;

		/*set ACL rule via calling multicast API*/
		ret = setRealMulticastRuleByProfile(instanceId, type, action, NULL, ruleRecord);
		if(ret != 0){
			ret = -1;
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setRealMulticastRuleByProfile fail\n",__LINE__, __func__);
			goto end;
		}
			
		/*get valid content in table*/
		if(findFlag == 1){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] find, modify this record\n", __LINE__, __func__);			
		}else{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]not find, add this record\n", __LINE__, __func__);	
			/*if not find, add this record*/
			tableSize += OMCI_MOP_ACL_TABLE_ENTRY_LENGTH;
		}
	
	} else if(action == OMCI_IGMP_ACL_TABLE_ENTRY_CLEAR_ACTION){//clear this table

		/*real clean record*/
		ret = clearRealMulticastRuleByProfileType(instanceId, type);		
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]clearRealMulticastRuleByProfileType fail\n",__LINE__, __func__);
			goto end;
		}
		tableSize = 0;	
	}
		
#if 0
	omciDumpTable(tmpValue_ptr, tableSize);
#endif

	ret = 0;
end:
	if(ret != 0){
		ret = -1;
	}

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, tableSize=%d\n",__LINE__, __func__, tableSize);
	return ret;
}

int setMOPMulticastDynamicAclTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t attrIndex = OMCI_MULTICAST_DYNAMIC_ACL_ATTR_INDEX;
	
	return setMOPMulticastAclTableValueByType(me_info, omci_attr, attrIndex);
}

int setMOPMulticastStaticAclTableValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t attrIndex = OMCI_MULTICAST_STATIC_ACL_ATTR_INDEX;
	
	return setMOPMulticastAclTableValueByType(me_info, omci_attr, attrIndex);
}


int setMOPMulticastRobustnessValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = -1;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;

	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	type = OMCI_MULTICAST_ROBUSTNESS_TYPE;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x\n",__LINE__, __func__, instanceId);
	
	if(setMOPMulticastAttrValue(instanceId, type, (char *)&multicast_op_attr->robustness) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}

	ret = 0;	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}

int setMOPMulticastQuerierIPAddressValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = -1;
	char queryip[16] = {0};
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;
	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	type = OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x\n",__LINE__, __func__, instanceId);
	memcpy(queryip, multicast_op_attr->querierIpAddr, 4);
	if(setMOPMulticastAttrValue(instanceId, type, queryip) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}
	
	ret = 0;	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}
int setMOPMulticastQueryIntervalValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = -1;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;
	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	type = OMCI_MULTICAST_QUERY_INTERVAL_TYPE;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x\n",__LINE__, __func__, instanceId);
	
	if(setMOPMulticastAttrValue(instanceId, type, (char *)&multicast_op_attr->queryInterval) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}
	
	ret = 0;	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}
int setMOPMulticastQueryMaxResponseTimeValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = -1;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;
	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	type = OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x\n",__LINE__, __func__, instanceId);
	
	if(setMOPMulticastAttrValue(instanceId, type, (char *)&multicast_op_attr->queryMaxRespTime) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}
	
	ret = 0;	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}
int setMOPMulticastLastMemberQueryIntervalValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = -1;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;
	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	type = OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x\n",__LINE__, __func__, instanceId);
	
	if(setMOPMulticastAttrValue(instanceId, type, (char *)&multicast_op_attr->lastMemberQueryInterval) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}
	
	ret = 0;	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}
int setMOPMulticastUnauthorizedJoinRequestValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = -1;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;
	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	type = OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, instId =%02x\n",__LINE__, __func__, instanceId);
	
	if(setMOPMulticastAttrValue(instanceId, type, (char *)&multicast_op_attr->unAuthJoinReqBehaviour) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setMOPMulticastAttrValue fail\n",__LINE__, __func__);
        ret = -1;
		goto end;
	}
	
	ret = 0;	
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}

int setMOPMulticastDownstreamIGMPAndTCIValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	int ret = -1;
	uint8_t tagCtrlVal = 0;
	uint16_t downStreamTCI = 0;
	uint16_t instanceId=0;
	uint16_t type = 0;
	omci_multicast_op_profile_ptr multicast_op_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	instanceId = me_info->inst_id;
	multicast_op_attr = (omci_multicast_op_profile_ptr)me_info->attributes;
    if(multicast_op_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	type = OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE;

	tagCtrlVal = *(uint8_t *)multicast_op_attr->downIgmpMultiTci;
	downStreamTCI = get16((uint8_t *)multicast_op_attr->downIgmpMultiTci+1);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]:tagCtrlVal = %x, downStreamTCI=%x\n", __LINE__, __func__, tagCtrlVal, downStreamTCI);
	
	switch(tagCtrlVal){
		case OMCI_MULTICAST_DOWN_TAG_CTRL_TRANSPARENT:
		case OMCI_MULTICAST_DOWN_TAG_CTRL_STRIP:
		case OMCI_MULTICAST_DOWN_TAG_CTRL_ADD_TCI:
		case OMCI_MULTICAST_DOWN_TAG_CTRL_REPLACE_TCI:
		case OMCI_MULTICAST_DOWN_TAG_CTRL_REPLACE_VID:			
			break;
		case OMCI_MULTICAST_DOWN_TAG_CTRL_ADD_TCI_USE_UNI:
		case OMCI_MULTICAST_DOWN_TAG_CTRL_REPLACE_TCI_USE_UNI:
		case OMCI_MULTICAST_DOWN_TAG_CTRL_REPLACE_VID_USE_UNI:
			break;
		default: //only update instance value
			if(MT_OMCI_MSG_TYPE_CREAT== me_info->msg_type){
				ret = 0;
			}
			goto end;
	}

	if(setMOPMulticastAttrValue(instanceId, type, multicast_op_attr->downIgmpMultiTci) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]:setMOPMulticastAttrValue, fail", __LINE__, __func__);
        ret = -1;
		goto end;
	}	

	ret = 0;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret=%02x\n",__LINE__, __func__, ret);
	return ret;
}


int omci_me_multicast_pro_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info){
	int ret = -1;
	uint16_t currInstId = 0;
	uint16_t type = 0;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_entry)||(NULL == me_info)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	currInstId = me_info->class_id;	

	type = ((OMCI_MULTICAST_VER_TYPE)
		| (OMCI_MULTICAST_FUNC_TYPE)
		| (OMCI_MULTICAST_FAST_LEAVE_TYPE)
		| (OMCI_MULTICAST_UP_TCI_TYPE)
		| (OMCI_MULTICAST_TAG_CTRL_TYPE)		
		| (OMCI_MULTICAST_MAX_RATE_TYPE)
		| (OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		| (OMCI_MULTICAST_STATIC_ACL_TYPE)
		| (OMCI_MULTICAST_ROBUSTNESS_TYPE)	
		| (OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)	
		| (OMCI_MULTICAST_QUERY_INTERVAL_TYPE)	
		| (OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE)	
		| (OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE)	
		| (OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)	
		| (OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE));

	ret = clearRealMulticastRuleByProfileType(currInstId, type);

end:
	return ret;
}

/*******************************************************************************************************************************
9.3.28 multicast subscriber config info

********************************************************************************************************************************/

int setMSCmeTypeValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint16_t currInstId = 0;
	uint8_t meType = 0;
	uint16_t clearType = 0;
	uint16_t multicastProfileInstId = 0;
	omci_me_info_t old_me_info = {0};
	omci_multicast_subs_cfg_info_ptr multicast_subs_cfg_info_attr_old = NULL;
	omci_multicast_subs_cfg_info_ptr multicast_subs_cfg_info_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	multicast_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info->attributes;
    if(multicast_subs_cfg_info_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get 9.3.28 ME  instance id*/
	currInstId = me_info->inst_id;
	multicastProfileInstId = multicast_subs_cfg_info_attr->multiOpProPointer;
	if ((multicastProfileInstId == 0x0) || (multicastProfileInstId == 0xffff))
	{
		ret = 0;	
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]multicastProfileInstId is NULL\n",__LINE__, __func__);
		goto end;
	}	

	/*set operation  type*/
	clearType = (( OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		| (OMCI_MULTICAST_STATIC_ACL_TYPE)
		| (OMCI_MULTICAST_MAX_RATE_TYPE)
		| (OMCI_MULTICAST_VER_TYPE)
		| (OMCI_MULTICAST_FUNC_TYPE)
		| (OMCI_MULTICAST_FAST_LEAVE_TYPE)
		| (OMCI_MULTICAST_UP_TCI_TYPE)
		| (OMCI_MULTICAST_TAG_CTRL_TYPE)		
		| (OMCI_MULTICAST_ROBUSTNESS_TYPE)	
		| (OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)	
		| (OMCI_MULTICAST_QUERY_INTERVAL_TYPE)	
		| (OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE) 
		| (OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE) 
		| (OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)	
		| (OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE));

	/*get old  me type value and clear*/
	old_me_info.class_id = OMCI_CLASS_ID_MULTICAST_SUBSCRIBER_CFG_INFO;
	old_me_info.inst_id = currInstId;
	if(omci_attr_get_old_data_except_table_attr(&old_me_info) == 0){
		multicast_subs_cfg_info_attr_old = (omci_multicast_subs_cfg_info_ptr)old_me_info.attributes;
		if(NULL == multicast_subs_cfg_info_attr_old){
	        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
			ret = -1;
			goto end;
		}
		meType = multicast_subs_cfg_info_attr_old->meType;

		/*clear old  real multicast rule by 9.3.28 me type attribute.*/
		ret = clearRealMulticastRuleByMeType(currInstId, meType, clearType);			
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]clearRealMulticastRuleByMeType fail,meType=%d,clearType=%d,\n",
				__LINE__, __func__,meType,clearType);
			goto end;
		}	
	}

	/*get new me type value*/
	meType = multicast_subs_cfg_info_attr->meType;

	/*set new rule by 9.3.28 me type*/
	ret = setRealMulticastRuleByMeType(currInstId, meType, clearType,multicastProfileInstId);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setRealMulticastRuleByMeType fail,meType=%d,clearType=%d,\n",
			__LINE__, __func__,meType,clearType);
		goto end;
	}
	
	ret = 0;
end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end, ret = %d\n",__LINE__, __func__, ret);
	return ret;
}

static int updateMSOperationProfile(uint16_t instanceId, uint8_t meType, uint16_t clearType,uint16_t multiProfId,uint8_t clearFlag)
{
	int ret = -1;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] enter subProfId %d,  multiOpeProfId %d\n",__LINE__, __func__,instanceId,multiProfId);


	/*update multicast operations profile pointer attribute value*/
	if ((multiProfId == 0x0) || (multiProfId == 0xffff))
	{
		ret = 0;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]multicastProfileInstId is NULL\n",__LINE__, __func__);
		goto end;
	}
	
	/*clear old  real multicast rule by 9.3.28 me type attribute.*/
	if(clearFlag){
		ret = clearRealMulticastRuleByMeType(instanceId, meType, clearType);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]clearRealMulticastRuleByMeType fail\n",__LINE__, __func__);
			goto end;
		}
	}
	/*set new rule by 9.3.28 me type*/
	ret = setRealMulticastRuleByMeType(instanceId, meType, clearType,multiProfId);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]setRealMulticastRuleByMeType is NULL\n",__LINE__, __func__);
	}

end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] end ret=%d\n",__LINE__, __func__,ret);
	return ret;	;
}

int setMSCOperationProfileValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint16_t currInstId = 0;
	uint8_t meType = 0;
	uint16_t clearType = 0;
	uint16_t multicastProfileInstId = 0;
	omci_multicast_subs_cfg_info_ptr multicast_subs_cfg_info_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start\n",__LINE__, __func__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

	currInstId = me_info->inst_id;
	
	multicast_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info->attributes;
    if(multicast_subs_cfg_info_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
	meType = multicast_subs_cfg_info_attr->meType;
	multicastProfileInstId = multicast_subs_cfg_info_attr->multiOpProPointer;
	
	/*set operation  type*/
	clearType = (( OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		| (OMCI_MULTICAST_STATIC_ACL_TYPE)
		| (OMCI_MULTICAST_MAX_RATE_TYPE)
		| (OMCI_MULTICAST_VER_TYPE)
		| (OMCI_MULTICAST_FUNC_TYPE)
		| (OMCI_MULTICAST_FAST_LEAVE_TYPE)
		| (OMCI_MULTICAST_UP_TCI_TYPE)
		| (OMCI_MULTICAST_TAG_CTRL_TYPE)		
		| (OMCI_MULTICAST_ROBUSTNESS_TYPE)	
		| (OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)	
		| (OMCI_MULTICAST_QUERY_INTERVAL_TYPE)	
		| (OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE)	
		| (OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE)	
		| (OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)	
		| (OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE));
	
	ret = updateMSOperationProfile(currInstId,meType, clearType,multicastProfileInstId,ENABLE);

	return ret;	
}

int setMSCMaxSimultaneousGroupValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint16_t val = 0;
	uint16_t currInstId = 0;
	uint8_t meType = 0;
	uint8_t portFlag = 0;
	uint16_t portId = 0;	
	int i;
	omci_multicast_subs_cfg_info_ptr multicast_subs_cfg_info_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start\n",__LINE__, __func__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get 9.3.28 ME  instance id*/
	currInstId = me_info->inst_id;
	
	/*get me type value*/
	multicast_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info->attributes;
    if(multicast_subs_cfg_info_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	meType = multicast_subs_cfg_info_attr->meType;
	
	val = multicast_subs_cfg_info_attr->maxSimuGroups;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start, currInstId=%d, meType=%d, val=%d\n", __LINE__, __func__,currInstId, meType, val);

	ret = getLanPortByMeType(currInstId, meType, &portFlag, &portId);
	if(ret != 0){
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]getLanPortByMeType fail\n",__LINE__, __func__);
		goto end;
	}
	
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG){
		ret = igmpONUSetMaxPlayNum(portId,val);

		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetMaxPlayNum fail\n",__LINE__, __func__);
		}		
	}else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG){
		for(i = 0; i<MAX_ETH_PORT_NUM; i++){
			portId = i+1;
			ret = igmpONUSetMaxPlayNum(portId,val);
			if(ret != 0){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%5d][%s]igmpONUSetMaxPlayNum fail\n",__LINE__, __func__);
			}
		}	
	}

	ret = 0;

end:
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]end\n",__LINE__, __func__);
	return ret;
}

int setMSCMaxBandwidthValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1, i = 0;
	uint32_t val = 0;
	uint16_t currInstId = 0, portId = 0;
	uint8_t meType = 0, portFlag = 0;
	omci_multicast_subs_cfg_info_ptr multicast_subs_cfg_info_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start\n",__LINE__, __func__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get 9.3.28 ME  instance id*/
	currInstId = me_info->inst_id;
	
	/*get me type value*/
	multicast_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info->attributes;
    if(multicast_subs_cfg_info_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	meType = multicast_subs_cfg_info_attr->meType;
	
	val = multicast_subs_cfg_info_attr->maxMultiBw;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][LN%d]start, currInstId=%d, meType=%d, val=%d\n",__FUNCTION__,__LINE__,currInstId, meType, val);

	ret = getLanPortByMeType(currInstId, meType, &portFlag, &portId);
	if(ret != 0)
	{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]getLanPortByMeType fail\n",__FUNCTION__,__LINE__);
		goto end;
	}
	
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG)
	{
		ret = igmpONUSetMaxBW(portId,val);

		if(ret != 0)
		{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]igmpONUSetMaxBW fail\n",__FUNCTION__,__LINE__);
		}		
	}
	else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG)
	{
		for(i = 0; i<MAX_ETH_PORT_NUM; i++)
		{
			portId = i+1;
			ret = igmpONUSetMaxBW(portId,val);
			if(ret != 0)
			{
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]igmpONUSetMaxBW fail\n",__FUNCTION__,__LINE__);
			}
		}	
	}

	ret = 0;
end:
	return ret;
}

int setMSCBWEnforcementValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1, i = 0;
	uint8_t val = 0;
	uint16_t currInstId = 0, portId = 0;
	uint8_t meType = 0, portFlag = 0;
	omci_multicast_subs_cfg_info_ptr multicast_subs_cfg_info_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start\n",__LINE__, __func__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get 9.3.28 ME  instance id*/
	currInstId = me_info->inst_id;
	
	/*get me type value*/
	multicast_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info->attributes;
    if(multicast_subs_cfg_info_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	meType = multicast_subs_cfg_info_attr->meType;
	
	val = multicast_subs_cfg_info_attr->bwEnforement;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][LN%d]start, currInstId=%d, meType=%d, val=%d\n",__FUNCTION__,__LINE__,currInstId, meType, val);

	ret = getLanPortByMeType(currInstId, meType, &portFlag, &portId);
	if(ret != 0)
	{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]getLanPortByMeType fail\n",__FUNCTION__,__LINE__);
		goto end;
	}
	
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG)
	{
		ret = igmpONUSetMaxEnforcement(portId,val);
		
		if(ret != 0)
		{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]igmpONUSetMaxBW fail\n",__FUNCTION__,__LINE__);
		}		
	}
	else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG)
	{
		for(i = 0; i<MAX_ETH_PORT_NUM; i++)
		{
			portId = i+1;
			ret = igmpONUSetMaxEnforcement(portId,val);
			if(ret != 0)
			{
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]igmpONUSetMaxBW fail\n",__FUNCTION__,__LINE__);
			}
		}	
	}

	ret = 0;
end:
	return ret;
}

int setMSCBWsrvPktTblValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint16_t currInstId = 0;
	uint8_t meType = 0;
	uint16_t clearType = 0;
	uint16_t multicastProfileInstId = 0;
	omci_multicast_subs_cfg_info_ptr multicast_subs_cfg_info_attr = NULL;
	omci_table_attr_ptr mcastSrvPktTbl_p = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s] start\n",__LINE__, __func__);
	if((NULL == me_info)||(NULL == omci_attr)){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
		return -1;
	}

	currInstId = me_info->inst_id;

	multicast_subs_cfg_info_attr = (omci_multicast_subs_cfg_info_ptr)me_info->attributes;
	if(multicast_subs_cfg_info_attr == NULL ){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
		return -1;
	}
	meType = multicast_subs_cfg_info_attr->meType;
	mcastSrvPktTbl_p = & multicast_subs_cfg_info_attr->multiSrvPackTable;
	if(mcastSrvPktTbl_p != NULL){
		multicastProfileInstId = get16((uint8_t *)&mcastSrvPktTbl_p->buf[MCAST_OP_PROF_OFFSET]);
	}
	else{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] mcastSrvPktTbl_p is NULL, fail\n",__FUNCTION__,__LINE__);
		return -1;
	}

	/*set operation  type*/
	clearType = (( OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		| (OMCI_MULTICAST_STATIC_ACL_TYPE)
		| (OMCI_MULTICAST_MAX_RATE_TYPE)
		| (OMCI_MULTICAST_VER_TYPE)
		| (OMCI_MULTICAST_FUNC_TYPE)
		| (OMCI_MULTICAST_FAST_LEAVE_TYPE)
		| (OMCI_MULTICAST_UP_TCI_TYPE)
		| (OMCI_MULTICAST_TAG_CTRL_TYPE)
		| (OMCI_MULTICAST_ROBUSTNESS_TYPE)
		| (OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)
		| (OMCI_MULTICAST_QUERY_INTERVAL_TYPE)
		| (OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE)
		| (OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE)
		| (OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)
		| (OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE));

	ret = updateMSOperationProfile(currInstId,meType, clearType,multicastProfileInstId,DISABLE);

	return ret;
}

int omci_me_multicast_sbs_cfg_info_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info){
	int ret = -1;
	uint16_t instId = 0;
	uint8_t meType = 0;
	uint16_t clearType = 0;	

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter %s [%d]\n",__FUNCTION__,__LINE__);
    if((NULL == me_entry)||(NULL == me_info)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	instId = me_info->class_id;	

	/*set clear type*/
	clearType = ((OMCI_MULTICAST_VER_TYPE)
		| (OMCI_MULTICAST_FUNC_TYPE)
		| (OMCI_MULTICAST_FAST_LEAVE_TYPE)
		| (OMCI_MULTICAST_UP_TCI_TYPE)
		| (OMCI_MULTICAST_TAG_CTRL_TYPE)		
		| (OMCI_MULTICAST_MAX_RATE_TYPE)
		| (OMCI_MULTICAST_DYNAMIC_ACL_TYPE)
		| (OMCI_MULTICAST_STATIC_ACL_TYPE)
		| (OMCI_MULTICAST_ROBUSTNESS_TYPE)	
		| (OMCI_MULTICAST_QUERIER_IP_ADDRESS_TYPE)	
		| (OMCI_MULTICAST_QUERY_INTERVAL_TYPE)	
		| (OMCI_MULTICAST_QUERY_MAX_RESPONSE_TIME_TYPE)	
		| (OMCI_MULTICAST_LAST_QUERY_INTERVAL_TYPE)	
		| (OMCI_MULTICAST_UNAUTHORIZED_JOIN_TYPE)	
		| (OMCI_MULTICAST_DOWN_IGMP_AND_TCI_TYPE));

	/*clear real multicast rule by 9.3.28 me type attribute.*/
	ret = clearRealMulticastRuleByMeType(instId, meType, clearType);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]clearRealMulticastRuleByMeType fail, ret =%d\n",__LINE__, __func__, ret);
		goto end;
	}

	ret = 0;
end:
	return ret;
}

/*******************************************************************************************************************************
9.3.29 multicast subscriber monitor

********************************************************************************************************************************/

int getMSMCurrMultBandwidthValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instanceId = 0;
	uint8_t meType = 0;
	uint8_t portFlag =0;
	uint16_t portId = 0;
	uint32_t cmbw = 0;
	uint32_t tmpcmbw = 0;
	int i = 0;
	int ret = -1; 
	omci_multicast_subs_monitor_ptr multicast_subs_monitor_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start\n",__LINE__, __func__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get instance id*/
	instanceId = me_info->inst_id;
	
	/*get 9.3.29  multicast subscriber monitorME me type attribute*/
	multicast_subs_monitor_attr = (omci_multicast_subs_monitor_ptr)me_info->attributes;
    if(multicast_subs_monitor_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	meType = multicast_subs_monitor_attr->meType;

	/*get lan  port information*/
	ret = getLanPortByMeType(instanceId, meType, &portFlag, &portId);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMCurrMultBandwidthValue-> getLanPortByMeType  fail");
		goto end;
	}
	
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG)
	{
		ret = igmpOnuGetCurrMultiBW(portId,&cmbw);

		if(ret != 0)
		{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]getMSMCurrMultBandwidthValue fail\n",__FUNCTION__,__LINE__);
		}		
	}
	else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG)
	{
		for(i = 0; i<MAX_ETH_PORT_NUM; i++)
		{
			portId = i+1;
			ret = igmpOnuGetCurrMultiBW(portId,&tmpcmbw);
			cmbw += tmpcmbw;
			if(ret != 0)
			{
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]getMSMCurrMultBandwidthValue fail\n",__FUNCTION__,__LINE__);
			}
		}	
	}
	multicast_subs_monitor_attr->curMultiBw = cmbw;
	ret = 0;
end:
	return ret;
}



int getMSMJoinMesgCounterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instanceId = 0;
	uint8_t meType = 0;
	uint8_t portFlag =0;
	uint16_t portId = 0;
	uint32_t joinNum = 0;
	uint32_t tmpjoinNum = 0;
	int i = 0;
	int ret = -1; 
	omci_multicast_subs_monitor_ptr multicast_subs_monitor_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start\n",__LINE__, __func__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get instance id*/
	instanceId = me_info->inst_id;
	
	/*get 9.3.29  multicast subscriber monitorME me type attribute*/
	multicast_subs_monitor_attr = (omci_multicast_subs_monitor_ptr)me_info->attributes;
    if(multicast_subs_monitor_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	meType = multicast_subs_monitor_attr->meType;

	/*get lan  port information*/
	ret = getLanPortByMeType(instanceId, meType, &portFlag, &portId);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMCurrMultBandwidthValue-> getLanPortByMeType  fail");
		goto end;
	}
	
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG)
	{
		ret = igmpOnuGetJoinMessCounter(portId,&joinNum);

		if(ret != 0)
		{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]getMSMCurrMultBandwidthValue fail\n",__FUNCTION__,__LINE__);
		}		
	}
	else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG)
	{
		for(i = 0; i<MAX_ETH_PORT_NUM; i++)
		{
			portId = i+1;
			ret = igmpOnuGetJoinMessCounter(portId,&tmpjoinNum);
			joinNum += tmpjoinNum;
			if(ret != 0)
			{
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]getMSMCurrMultBandwidthValue fail\n",__FUNCTION__,__LINE__);
			}
		}	
	}

	multicast_subs_monitor_attr->joinMsgCnt = joinNum;
	ret = 0;
end:
	return ret;
}

int getMSMBandExceCounterValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr)
{
	uint16_t instanceId = 0;
	uint8_t meType = 0;
	uint8_t portFlag =0;
	uint16_t portId = 0;
	uint32_t bwexNum = 0;
	uint32_t tmpbwexNum = 0;
	int i = 0;
	int ret = -1; 
	omci_multicast_subs_monitor_ptr multicast_subs_monitor_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start\n",__LINE__, __func__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get instance id*/
	instanceId = me_info->inst_id;
	
	/*get 9.3.29  multicast subscriber monitorME me type attribute*/
	multicast_subs_monitor_attr = (omci_multicast_subs_monitor_ptr)me_info->attributes;
    if(multicast_subs_monitor_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	meType = multicast_subs_monitor_attr->meType;

	/*get lan  port information*/
	ret = getLanPortByMeType(instanceId, meType, &portFlag, &portId);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMCurrMultBandwidthValue-> getLanPortByMeType  fail");
		goto end;
	}
	
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG)
	{
		ret = igmpOnuGetBWExceCounter(portId,&bwexNum);

		if(ret != 0)
		{
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]getMSMCurrMultBandwidthValue fail\n",__FUNCTION__,__LINE__);
		}		
	}
	else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG)
	{
		for(i = 0; i<MAX_ETH_PORT_NUM; i++)
		{
			portId = i+1;
			ret = igmpOnuGetBWExceCounter(portId,&tmpbwexNum);
			bwexNum += tmpbwexNum;
			if(ret != 0)
			{
				omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][LN%d]getMSMCurrMultBandwidthValue fail\n",__FUNCTION__,__LINE__);
			}
		}	
	}

	multicast_subs_monitor_attr->bwExceedCnt= bwexNum;
	ret = 0;
end:
	return ret;
}


int getMSMIpv4ActiveGroupTblValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint32_t tableSize = 0;
	uint16_t maxBytes = 0;
	uint8_t groupListNum = 0;
	uint8_t * tableBuffer_ptr = NULL;
	uint16_t instanceId = 0;
	uint8_t meType = 0;
	uint8_t portFlag =0;
	uint16_t portId = 0;
	int i = 0;
	int j = 0;
	uint16_t type = OMCI_MULTICAST_DYNAMIC_ACL_TYPE;
	uint8_t * temp1_ptr = NULL;
	uint8_t time = 0;
	uint8_t protocol = OMCI_IPV4_PROTOCOL;
	int totalFwdentryCnt = 0;

	omciIgmpActiveGroupInfo_ptr rule_ptr = NULL;
	omciIgmpActiveGroupInfo_ptr tempRule_ptr = NULL;
	omci_multicast_subs_monitor_ptr multicast_subs_monitor_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start\n",__LINE__, __func__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	
	/*get instance id*/
	instanceId = me_info->inst_id;
	
	/*get 9.3.29  multicast subscriber monitorME me type attribute*/
	multicast_subs_monitor_attr = (omci_multicast_subs_monitor_ptr)me_info->attributes;
    if(multicast_subs_monitor_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	meType = multicast_subs_monitor_attr->meType;

	//check xpon_igmp fwdentry cnt
	totalFwdentryCnt = igmp_get_fwdentry_cnt();
	if(totalFwdentryCnt <=  0){
		multicast_subs_monitor_attr->ipv4ActGroupListTable.len = 0;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_NO_MSG,"totalFwdentryCnt = 0\n");
		ret = 0;
		goto end;
	}

	/*malloc space for get a port active group list value*/
	maxBytes = totalFwdentryCnt * sizeof(omciIgmpActiveGroupInfo_t);
	rule_ptr = (omciIgmpActiveGroupInfo_ptr)calloc(1, maxBytes);
	if(rule_ptr == NULL){
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv4ActiveGroupTblValue -->rule_ptr is NULL, calloc fail");
		goto end;
	}

	tableBuffer_ptr = (uint8_t *)multicast_subs_monitor_attr->ipv4ActGroupListTable.buf;
	if(tableBuffer_ptr == NULL){
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv4ActiveGroupTblValue -->tableBuffer_ptr is NULL, fail");
		goto end;
	}

	/*get lan  port information*/
	ret = getLanPortByMeType(instanceId, meType, &portFlag, &portId);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv4ActiveGroupTblValue-> getLanPortByMeType  fail");
		goto end;
	}
	
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG){		
		time = 1;
	}else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG){
		time = MAX_ETH_PORT_NUM;			
	}else{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv4ActiveGroupTblValue-> portFlag  fail");
		goto end;
	}

	tableSize = 0;
	/*get ipv4 dynamic active group list*/
	for(i = 0; i<time; i++){
		if(time == MAX_ETH_PORT_NUM){
			portId = i+1; //igmp valid value (1~4)
		}

		/*call Multicast dynamic access list table API*/
		groupListNum = 0;
		memset(rule_ptr, 0, maxBytes);
		ret = igmpONUGetActiveGroupList(portId, protocol, totalFwdentryCnt,type, &groupListNum, (igmpActiveGroupInfo_t*)rule_ptr);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv4ActiveGroupTblValue-> igmpONUGetActiveGroupList  fail");
			continue;
		}
		
		/*get ipv4 dynamic active access list*/
		for(j = 0; j<groupListNum; j ++){
			if(tableSize + OMCI_IPV4_ACTIVE_MLTICAST_GROUP_RECORD_SIZE > OMCI_MAX_TABLE_SIZE){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_NO_MSG,"groupListNum=%d exceed maxNumSupport=%d\n",groupListNum,OMCI_MAX_TABLE_SIZE/OMCI_IPV4_ACTIVE_MLTICAST_GROUP_RECORD_SIZE);
				break;
			}

			tempRule_ptr = rule_ptr+j;
			temp1_ptr = tableBuffer_ptr + tableSize;
			/*vid*/
			put16(temp1_ptr, tempRule_ptr->vid);
			temp1_ptr += 2;
			
			/*source ip*/
			memcpy(temp1_ptr, tempRule_ptr->srcIp+OMCI_MAX_IPV4_PREFIX, 4);
			temp1_ptr +=4;
			
			/*multicast dest ip*/
			memcpy(temp1_ptr, tempRule_ptr->multiDestIp+OMCI_MAX_IPV4_PREFIX, 4);
			temp1_ptr +=4;

			/*best bandwidth*/
			put32(temp1_ptr, tempRule_ptr->bestBandWidth);
			temp1_ptr +=4;
			
			/*client ip*/
			memcpy(temp1_ptr, tempRule_ptr->clientIp+OMCI_MAX_IPV4_PREFIX, 4);
			temp1_ptr +=4;
			
			/*time(4bytes)*/
			put32(temp1_ptr, tempRule_ptr->time);
			temp1_ptr +=4;

			/*reserved(2bytes)*/
			put16(temp1_ptr, 0);
			temp1_ptr += 2;

			tableSize += OMCI_IPV4_ACTIVE_MLTICAST_GROUP_RECORD_SIZE;
		}		
	}

	multicast_subs_monitor_attr->ipv4ActGroupListTable.len = tableSize;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_NO_MSG,"tableSize=%d",tableSize);

	ret = 0;
end:	
	if(rule_ptr != NULL){
		free(rule_ptr);
		rule_ptr = NULL;
	}

	return ret;
}


int getMSMIpv6ActiveGroupTblValue(omci_me_info_ptr me_info, omci_attr_dscp_ptr omci_attr){
	int ret = -1;
	uint32_t tableSize = 0;
	uint16_t maxBytes = 0;
	uint8_t groupListNum = 0;
	uint8_t * tableBuffer_ptr = NULL;
	uint16_t instanceId = 0;
	uint8_t meType = 0;
	uint8_t portFlag =0;
	uint16_t portId = 0;
	int i = 0;
	int j = 0;
	uint16_t type = OMCI_MULTICAST_DYNAMIC_ACL_TYPE;
	uint8_t * temp1_ptr = NULL;
	uint8_t time = 0;
	uint8_t protocol = OMCI_IPV6_PROTOCOL;
	int totalFwdentryCnt = 0;

	omciIgmpActiveGroupInfo_ptr rule_ptr = NULL;
	omciIgmpActiveGroupInfo_ptr tempRule_ptr = NULL;
	omci_multicast_subs_monitor_ptr multicast_subs_monitor_attr = NULL;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%5d][%s]start\n",__LINE__, __func__);
    if((NULL == me_info)||(NULL == omci_attr)){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] parameter is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }

	/*get instance id*/
	instanceId = me_info->inst_id;
	
	/*get 9.3.29  multicast subscriber monitorME me type attribute*/
	multicast_subs_monitor_attr = (omci_multicast_subs_monitor_ptr)me_info->attributes;
    if(multicast_subs_monitor_attr == NULL ){
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, " %s [%d] attributes is NULL, fail\n",__FUNCTION__,__LINE__);
        ret = -1;
        goto end;
    }
	meType = multicast_subs_monitor_attr->meType;

	//check xpon_igmp fwdentry cnt
	totalFwdentryCnt = igmp_get_fwdentry_cnt();
	if(totalFwdentryCnt <=  0){
		multicast_subs_monitor_attr->ipv6ActGroupListTable.len = 0;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_NO_MSG,"totalFwdentryCnt = 0\n");
		ret = 0;
		goto end;
	}

	/*malloc space for get a port active group list value*/
	maxBytes = totalFwdentryCnt * sizeof(omciIgmpActiveGroupInfo_t);
	rule_ptr = (omciIgmpActiveGroupInfo_ptr)calloc(1, maxBytes);
	if(rule_ptr == NULL){
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv4ActiveGroupTblValue -->rule_ptr is NULL, calloc fail");
		goto end;
	}
	
	/*malloc space for all ipv6 active dynamic group list*/
	tableBuffer_ptr = (uint8_t *)multicast_subs_monitor_attr->ipv6ActGroupListTable.buf;
	if(tableBuffer_ptr == NULL){
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv4ActiveGroupTblValue -->tableBuffer_ptr is NULL, calloc fail");
		goto end;
	}	

	/*get lan  port information*/
	ret = getLanPortByMeType(instanceId, meType, &portFlag, &portId);
	if(ret != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv6ActiveGroupTblValue-> getLanPortByMeType  fail");
		goto end;
	}
	
	if(portFlag == OMCI_MULTICAST_ONE_PORT_FLAG){		
		time = 1;
	}else if(portFlag == OMCI_MULTICAST_ALL_PORT_FLAG){
		time = MAX_ETH_PORT_NUM;			
	}else{
		ret = -1;
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv6ActiveGroupTblValue-> portFlag  fail");
		goto end;
	}

	tableSize = 0;
	/*get ipv6 dynamic active group list*/
	for(i = 0; i<time; i++){
		if(time == MAX_ETH_PORT_NUM){
			portId = i+1; //igmp valid value (1~4)
		}
		/*call Multicast dynamic access list table API*/
		groupListNum = 0;
		memset(rule_ptr, 0, maxBytes);
		ret = igmpONUGetActiveGroupList(portId, protocol, totalFwdentryCnt,type, &groupListNum, (igmpActiveGroupInfo_t*)rule_ptr);
		if(ret != 0){
			omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "\r\n getMSMIpv6ActiveGroupTblValue-> igmpONUGetActiveGroupList  fail");
			continue;
		}
		
		/*get ipv6 dynamic active access list*/
		for(j = 0; j<groupListNum; j ++){
			if(tableSize + OMCI_IPV6_ACTIVE_MLTICAST_GROUP_RECORD_SIZE > OMCI_MAX_TABLE_SIZE){
				omcidbgPrintf(OMCI_DEBUG_LEVEL_NO_MSG,"groupListNum=%d exceed maxNumSupport=%d\n",groupListNum,OMCI_MAX_TABLE_SIZE/OMCI_IPV6_ACTIVE_MLTICAST_GROUP_RECORD_SIZE);
				break;
			}

			tempRule_ptr = rule_ptr+j;
			temp1_ptr = tableBuffer_ptr + tableSize;
			/*vid*/
			put16(temp1_ptr, tempRule_ptr->vid);
			temp1_ptr += 2;
			
			/*source ip*/
			memcpy(temp1_ptr, tempRule_ptr->srcIp, 16);
			temp1_ptr +=16;
			
			/*multicast dest ip*/
			memcpy(temp1_ptr, tempRule_ptr->multiDestIp, 16);
			temp1_ptr +=16;

			/*best bandwidth*/
			put32(temp1_ptr, tempRule_ptr->bestBandWidth);
			temp1_ptr +=4;
			
			/*client ip*/
			memcpy(temp1_ptr, tempRule_ptr->clientIp, 16);
			temp1_ptr +=16;
			
			/*time(4bytes)*/
			put32(temp1_ptr, tempRule_ptr->time);
			temp1_ptr +=4;

			tableSize += OMCI_IPV6_ACTIVE_MLTICAST_GROUP_RECORD_SIZE;
		}		
	}

	multicast_subs_monitor_attr->ipv6ActGroupListTable.len = tableSize;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_NO_MSG,"tableSize=%d",tableSize);

	ret = 0;
end:	
	if(rule_ptr != NULL){
		free(rule_ptr);
		rule_ptr = NULL;
	}
	return ret;
}

